Skip to content
Snippets Groups Projects
Verified Commit 3e886c50 authored by rahix's avatar rahix
Browse files

feat(light-sensor): Add ADC locking


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent abe89091
No related branches found
No related tags found
No related merge requests found
#include "FreeRTOS.h"
#include "timers.h"
#include "led.h"
#include "epicardium.h"
#include "modules/log.h"
#include "modules/modules.h"
#include "mxc_config.h"
#include "led.h"
#include "adc.h"
#include "gpio.h"
#include <errno.h>
#include "FreeRTOS.h"
#include "timers.h"
#define READ_FREQ pdMS_TO_TICKS(100)
......@@ -25,12 +29,25 @@ static int light_sensor_init()
static void readAdcCallback()
{
if (hwlock_acquire(HWLOCK_ADC, 0) != 0) {
/* Can't do much about this here ... Retry next time */
return;
}
ADC_StartConvert(ADC_CH_7, 0, 0);
ADC_GetData(&last_value);
hwlock_release(HWLOCK_ADC);
}
int epic_light_sensor_run()
{
int ret = 0;
if (hwlock_acquire(HWLOCK_ADC, pdMS_TO_TICKS(500)) != 0) {
return -EBUSY;
}
light_sensor_init();
if (!poll_timer) {
......@@ -47,10 +64,12 @@ int epic_light_sensor_run()
}
if (xTimerIsTimerActive(poll_timer) == pdFALSE) {
if (xTimerStart(poll_timer, 0) != pdPASS) {
return -EBUSY;
ret = -EBUSY;
}
}
return 0;
hwlock_release(HWLOCK_ADC);
return ret;
}
int epic_light_sensor_stop()
......@@ -63,6 +82,7 @@ int epic_light_sensor_stop()
if (xTimerStop(poll_timer, 0) != pdPASS) {
return -EBUSY;
}
return 0;
}
......
......@@ -42,6 +42,7 @@ void hwlock_init(void);
enum hwlock_periph {
HWLOCK_I2C = 0,
HWLOCK_ADC,
_HWLOCK_MAX,
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment