Skip to content

Commit

Permalink
Changes requested in PR SRA-VJTI#89
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperChamp234 committed Jan 30, 2024
1 parent e9bf1a7 commit 0f31981
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
21 changes: 16 additions & 5 deletions include/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h"
Expand All @@ -43,12 +42,17 @@

#define ADC_ATTEN ADC_ATTEN_DB_11

//define a struct that holds the adc1 handle and calibration handles for five channels in an array

/**
* @brief Structure representing an ADC object.
*
* This structure holds the handles and calibration data for an ADC.
*/
typedef struct
{
adc_oneshot_unit_handle_t adc1_handle;
adc_cali_handle_t adc1_cali_handle[5];
bool do_calib[5];
adc_oneshot_unit_handle_t adc1_handle; /**< Handle for ADC1 oneshot unit. */
adc_cali_handle_t adc1_cali_handle[5]; /**< Array of calibration handles for ADC1. */
bool do_calib[5]; /**< Array indicating whether calibration should be performed for each channel. */
} adc_obj_t;

typedef adc_obj_t* adc_handle_t;
Expand All @@ -60,6 +64,13 @@ typedef adc_obj_t* adc_handle_t;
**/
esp_err_t enable_adc1(adc_obj_t** adc_obj);

/**
* @brief Reads the adc value from the GPIO(channel) specified.
*
* @param adc_handle_t adc_handle - pointer to adc object.
* @param int gpio - gpio pin number of the channel to be read.
* @return int - returns the adc value read from the channel.
**/
int read_adc(adc_handle_t adc_handle, int gpio);

#endif
2 changes: 1 addition & 1 deletion include/sra_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
#include "oled.h"
#endif

#endif
#endif
3 changes: 0 additions & 3 deletions src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ esp_err_t config_adc1(adc_obj_t *adc_obj)
.bitwidth = ADC_BITWIDTH_12,
.atten = ADC_ATTEN,
};
ESP_LOGI(TAG, "ADC1 handle address: %p", adc_obj->adc1_handle);
//assign channels to each io in adc_io
for (int i = 0; i < sizeof(adc_io) / sizeof(adc_io[0]); i++)
{
Expand Down Expand Up @@ -116,10 +115,8 @@ esp_err_t enable_adc1(adc_obj_t** adc_obj)
.unit_id = ADC_UNIT_1,
};
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &ret->adc1_handle));
ESP_LOGI(TAG, "Handle address: %p", ret->adc1_handle);
config_adc1(ret);
calib_init(ret);
//assign return value to adc_handle
*adc_obj = ret;

return ESP_OK;
Expand Down

0 comments on commit 0f31981

Please sign in to comment.