Add basic ADC support

Planning on abstracting this behind hardware setup APIs, but this works
for a simple demo until then
This commit is contained in:
Aaron Cook 2025-09-08 15:38:08 -05:00
commit d439778949
9 changed files with 151 additions and 0 deletions

27
routines/photosensor.c Normal file
View file

@ -0,0 +1,27 @@
#include <zephyr/kernel.h>
#include "includes/ble.h"
#include "includes/routine.h"
#include "includes/hardware/adc.h"
routine_return_e
photosensor()
{
while (routine_status() == ROUTINE_STATUS_RUNNING) {
int32_t adc_mv = adc_get_mv(0);
char buf[16];
size_t print_len;
if (adc_mv == INT32_MIN) {
ble_set_telemetry_data("Reading failed", 14);
} else {
print_len = snprintk(buf, sizeof(buf), "%dmV", adc_mv);
ble_set_telemetry_data(buf, print_len);
}
routine_delay(500);
routine_yield();
}
return ROUTINE_RETURN_SUCCESS;
}