expose wake pin parameter and more tweaks

This commit is contained in:
microDev 2020-12-19 20:54:36 +05:30
parent a60fabdffa
commit ecd7c0878e
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
4 changed files with 54 additions and 16 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-18 12:42+0530\n"
"POT-Creation-Date: 2020-12-18 20:40+0530\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1463,6 +1463,10 @@ msgstr ""
msgid "Only one alarm.time alarm can be set."
msgstr ""
#: ports/esp32s2/common-hal/alarm/__init__.c
msgid "Only one alarm.touch alarm can be set."
msgstr ""
#: shared-module/displayio/ColorConverter.c
msgid "Only one color can be transparent at a time"
msgstr ""
@ -1837,6 +1841,10 @@ msgstr ""
msgid "Total data to write is larger than outgoing_packet_length"
msgstr ""
#: ports/esp32s2/common-hal/alarm/__init__.c
msgid "TouchAlarm not available in light sleep"
msgstr ""
#: py/obj.c
msgid "Traceback (most recent call last):\n"
msgstr ""

View File

@ -103,6 +103,7 @@ mp_obj_t common_hal_alarm_get_wake_alarm(void) {
// Set up light sleep or deep sleep alarms.
STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) {
bool time_alarm_set = false;
bool touch_alarm_set = false;
alarm_time_time_alarm_obj_t *time_alarm = MP_OBJ_NULL;
for (size_t i = 0; i < n_alarms; i++) {
@ -115,7 +116,16 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t
time_alarm = MP_OBJ_TO_PTR(alarms[i]);
time_alarm_set = true;
} else if (MP_OBJ_IS_TYPE(alarms[i], &alarm_touch_touchalarm_type)) {
alarm_touch_touchalarm_set_alarm(MP_OBJ_TO_PTR(alarms[i]));
if (!touch_alarm_set) {
if (deep_sleep) {
alarm_touch_touchalarm_set_alarm(MP_OBJ_TO_PTR(alarms[i]));
touch_alarm_set = true;
} else {
mp_raise_NotImplementedError(translate("TouchAlarm not available in light sleep"));
}
} else {
mp_raise_ValueError(translate("Only one alarm.touch alarm can be set."));
}
}
}

View File

@ -35,6 +35,7 @@ void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *s
if (pin->touch_channel == TOUCH_PAD_MAX) {
mp_raise_ValueError(translate("Invalid pin"));
}
claim_pin(pin);
self->pin = pin;
}
@ -64,15 +65,15 @@ mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t
return alarm;
}
static uint16_t sleep_touch_pin;
static touch_pad_t touch_channel = TOUCH_PAD_MAX;
void alarm_touch_touchalarm_set_alarm(alarm_touch_touchalarm_obj_t *self) {
sleep_touch_pin |= 1 << self->pin->number;
touch_channel = (touch_pad_t)self->pin->number;
esp_sleep_enable_touchpad_wakeup();
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
}
static void configure_sleep_touch_pin(touch_pad_t touch_channel) {
void alarm_touch_touchalarm_prepare_for_deep_sleep(void) {
// intialize touchpad
peripherals_touch_init(touch_channel);
@ -88,18 +89,10 @@ static void configure_sleep_touch_pin(touch_pad_t touch_channel) {
touch_pad_sleep_set_threshold(touch_channel, touch_value * 0.1); //10%
}
void alarm_touch_touchalarm_prepare_for_deep_sleep(void) {
for (uint8_t i = 1; i <= 14; i++) {
if ((sleep_touch_pin & 1 << i) != 0) {
configure_sleep_touch_pin((touch_pad_t)i);
}
}
}
bool alarm_touch_touchalarm_woke_us_up(void) {
return false;
}
void alarm_touch_touchalarm_reset(void) {
sleep_touch_pin = 0;
touch_channel = TOUCH_PAD_MAX;
}

View File

@ -27,13 +27,18 @@
#include "shared-bindings/alarm/touch/TouchAlarm.h"
#include "shared-bindings/board/__init__.h"
#include "py/objproperty.h"
//| class TouchAlarm:
//| """Trigger an alarm when touch is detected."""
//|
//| def __init__(self, *pin: microcontroller.Pin) -> None:
//| """Create an alarm that will be triggered when the
//| given pin is touched.
//| """Create an alarm that will be triggered when the given pin is touched.
//| The alarm is not active until it is passed to an `alarm`-enabling function, such as
//| `alarm.light_sleep_until_alarms()` or `alarm.exit_and_deep_sleep_until_alarms()`.
//|
//| :param microcontroller.Pin pin: The pin to monitor. On some ports, the choice of pin
//| may be limited due to hardware restrictions, particularly for deep-sleep alarms.
//| """
//| ...
//|
@ -57,8 +62,30 @@ STATIC mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}
//| pin: microcontroller.Pin
//| """The trigger pin."""
//|
STATIC mp_obj_t alarm_touch_touchalarm_obj_get_pin(mp_obj_t self_in) {
alarm_touch_touchalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_FROM_PTR(self->pin);
}
MP_DEFINE_CONST_FUN_OBJ_1(alarm_touch_touchalarm_get_pin_obj, alarm_touch_touchalarm_obj_get_pin);
const mp_obj_property_t alarm_touch_touchalarm_pin_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&alarm_touch_touchalarm_get_pin_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t alarm_touch_touchalarm_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_touch_touchalarm_pin_obj) },
};
STATIC MP_DEFINE_CONST_DICT(alarm_touch_touchalarm_locals_dict, alarm_touch_touchalarm_locals_dict_table);
const mp_obj_type_t alarm_touch_touchalarm_type = {
{ &mp_type_type },
.name = MP_QSTR_TouchAlarm,
.make_new = alarm_touch_touchalarm_make_new,
.locals_dict = (mp_obj_t)&alarm_touch_touchalarm_locals_dict,
};