Commit ce4a3ac8 authored by Rahix's avatar Rahix
Browse files

Merge 'direct light-sensor readout'

See merge request card10/firmware!236
parents 83a19117 b927b5de
Pipeline #3513 passed with stages
in 1 minute and 29 seconds
......@@ -102,6 +102,7 @@ typedef _Bool bool;
#define API_LIGHT_SENSOR_RUN 0x80
#define API_LIGHT_SENSOR_GET 0x81
#define API_LIGHT_SENSOR_STOP 0x82
#define API_LIGHT_SENSOR_READ 0x83
#define API_BUTTONS_READ 0x90
......@@ -1399,6 +1400,14 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value));
*/
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
*/
API(API_LIGHT_SENSOR_READ, uint16_t epic_light_sensor_read(void));
/**
* File
* ====
......
......@@ -27,6 +27,13 @@ static int light_sensor_init()
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()
{
if (hwlock_acquire(HWLOCK_ADC, 0) != 0) {
......
......@@ -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_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[] = {
{ 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_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(
light_sensor_module_globals, light_sensor_module_globals_table
......
......@@ -97,6 +97,7 @@ Q(light_sensor)
Q(start)
Q(get_reading)
Q(stop)
Q(read)
/* bme680 */
Q(bme680)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment