Skip to content
Snippets Groups Projects
Commit a345b8cf authored by fleur's avatar fleur
Browse files

DIRECT IR LED ADC READOUT NO LIMITS GO NUTS

parent 51c6d605
No related branches found
No related tags found
2 merge requests!260blinkisync as preload,!236issue 118 ambient light sensor max framerate
...@@ -102,6 +102,7 @@ typedef _Bool bool; ...@@ -102,6 +102,7 @@ typedef _Bool bool;
#define API_LIGHT_SENSOR_RUN 0x80 #define API_LIGHT_SENSOR_RUN 0x80
#define API_LIGHT_SENSOR_GET 0x81 #define API_LIGHT_SENSOR_GET 0x81
#define API_LIGHT_SENSOR_STOP 0x82 #define API_LIGHT_SENSOR_STOP 0x82
#define API_LIGHT_SENSOR_READ 0x83
#define API_BUTTONS_READ 0x90 #define API_BUTTONS_READ 0x90
...@@ -1386,6 +1387,16 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value)); ...@@ -1386,6 +1387,16 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value));
*/ */
API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop()); API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop());
/**
* Get the light level directly. Each call has an intrinsic delay of about 240us, I recommend another 100-300us delay via utime.sleep_ms() between calls. Whether or not the IR LED is fast enough is another issue.
*
* :return: Light level
*
* - ``-ENODATA``: Continuous readout not currently running.
*/
API(API_LIGHT_SENSOR_READ, uint16_t epic_light_sensor_read(void));
/** /**
* File * File
* ==== * ====
......
...@@ -27,6 +27,13 @@ static int light_sensor_init() ...@@ -27,6 +27,13 @@ static int light_sensor_init()
return 0; return 0;
} }
uint16_t epic_light_sensor_read()
{
ADC_StartConvert(ADC_CH_7, 0, 0);
ADC_GetData(&last_value);
return last_value;
}
static void readAdcCallback() static void readAdcCallback()
{ {
if (hwlock_acquire(HWLOCK_ADC, 0) != 0) { if (hwlock_acquire(HWLOCK_ADC, 0) != 0) {
......
...@@ -42,11 +42,18 @@ static mp_obj_t mp_light_sensor_stop() ...@@ -42,11 +42,18 @@ static mp_obj_t mp_light_sensor_stop()
} }
static MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_stop_obj, mp_light_sensor_stop); static MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_stop_obj, mp_light_sensor_stop);
static mp_obj_t mp_light_sensor_read()
{
return mp_obj_new_int_from_uint(epic_light_sensor_read());
}
static MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_read_obj, mp_light_sensor_read);
static const mp_rom_map_elem_t light_sensor_module_globals_table[] = { static const mp_rom_map_elem_t light_sensor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_light_sensor) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_light_sensor) },
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&light_sensor_start_obj) }, { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&light_sensor_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&light_sensor_stop_obj) }, { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&light_sensor_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_reading), MP_ROM_PTR(&light_sensor_get_obj) } { MP_ROM_QSTR(MP_QSTR_get_reading), MP_ROM_PTR(&light_sensor_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&light_sensor_read_obj) },
}; };
static MP_DEFINE_CONST_DICT( static MP_DEFINE_CONST_DICT(
light_sensor_module_globals, light_sensor_module_globals_table light_sensor_module_globals, light_sensor_module_globals_table
......
...@@ -97,6 +97,7 @@ Q(light_sensor) ...@@ -97,6 +97,7 @@ Q(light_sensor)
Q(start) Q(start)
Q(get_reading) Q(get_reading)
Q(stop) Q(stop)
Q(read)
/* bme680 */ /* bme680 */
Q(bme680) Q(bme680)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment