mirror of
https://github.com/m5stack/M5Stack_MicroPython.git
synced 2026-09-17 00:30:38 -07:00
Updated UART module
Updated display module, added methods to get/set default background and foreground colors Updated neopixel module added method info() which returns the neopixel instance configuration get() method can now return tuple of neopixel colors Fixed ALLHIGH constant in RTC module
This commit is contained in:
@@ -64,8 +64,11 @@ STATIC void machine_neopixel_print(const mp_print_t *print, mp_obj_t self_in, mp
|
||||
machine_neopixel_obj_t *self = self_in;
|
||||
|
||||
if (self->px.pixels != NULL) {
|
||||
mp_printf(print, "Neopixel(Pin=%d, Pixels: %d, bit/pix=%d, RMTChannel=%d, PixBufLen=%u, Color order: %s\n",
|
||||
self->gpio_num, self->px.pixel_count, self->px.nbits, self->channel, sizeof(uint32_t) * self->px.pixel_count, self->px.color_order);
|
||||
char colorder[5];
|
||||
sprintf(colorder, self->px.color_order);
|
||||
if (self->px.nbits == 24) colorder[3] = '\0';
|
||||
mp_printf(print, "Neopixel(Pin=%d, Pixels: %d, bit/pix=%d, RMTChannel=%d, PixBufLen=%u, Color order: '%s'\n",
|
||||
self->gpio_num, self->px.pixel_count, self->px.nbits, self->channel, sizeof(uint32_t) * self->px.pixel_count, colorder);
|
||||
mp_printf(print, " Timings (ns): T1H=%d, T1L=%d, T0H=%d, T0L=%d, Treset=%d\n)",
|
||||
self->px.timings.mark.duration0 * RMT_PERIOD_NS, self->px.timings.mark.duration1 * RMT_PERIOD_NS,
|
||||
self->px.timings.space.duration0 * RMT_PERIOD_NS, self->px.timings.space.duration1 * RMT_PERIOD_NS,
|
||||
@@ -400,32 +403,56 @@ STATIC mp_obj_t machine_neopixel_setHSB_int(size_t n_args, const mp_obj_t *pos_a
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_neopixel_setHSB_int_obj, 5, machine_neopixel_setHSB_int);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
STATIC mp_obj_t machine_neopixel_get(mp_obj_t self_in, mp_obj_t pos_in)
|
||||
//-----------------------------------------------------------------------
|
||||
STATIC mp_obj_t machine_neopixel_get(size_t n_args, const mp_obj_t *args)
|
||||
{
|
||||
machine_neopixel_obj_t *self = self_in;
|
||||
machine_neopixel_obj_t *self = args[0];
|
||||
np_check(self);
|
||||
|
||||
int pos = mp_obj_get_int(pos_in);
|
||||
uint8_t white;
|
||||
uint32_t icolor;
|
||||
int pos = mp_obj_get_int(args[1]);
|
||||
if (pos < 1) pos = 1;
|
||||
if (pos > self->px.pixel_count) pos = self->px.pixel_count;
|
||||
int cnt = 0;
|
||||
if (n_args > 2) {
|
||||
cnt = mp_obj_get_int(args[2]);
|
||||
if (cnt < 1) cnt = 1;
|
||||
if ((cnt + pos - 1) > self->px.pixel_count) cnt = self->px.pixel_count - pos + 1;
|
||||
}
|
||||
if (cnt < 2) {
|
||||
icolor = np_get_pixel_color(&self->px, pos-1, &white);
|
||||
if (self->px.nbits == 24) {
|
||||
return mp_obj_new_int(icolor);
|
||||
}
|
||||
else {
|
||||
mp_obj_t tuple[2];
|
||||
|
||||
uint8_t white;
|
||||
uint32_t icolor = np_get_pixel_color(&self->px, pos-1, &white);
|
||||
if (self->px.nbits == 24) {
|
||||
return mp_obj_new_int(icolor);
|
||||
tuple[0] = mp_obj_new_int(icolor);
|
||||
tuple[1] = mp_obj_new_int(white);
|
||||
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mp_obj_t tuple[2];
|
||||
mp_obj_t pix_tuple[cnt];
|
||||
mp_obj_t tuple[2];
|
||||
for (int i=0; i<cnt; i++) {
|
||||
icolor = np_get_pixel_color(&self->px, pos+i-1, &white);
|
||||
if (self->px.nbits == 24) {
|
||||
pix_tuple[i] = mp_obj_new_int(icolor);
|
||||
}
|
||||
else {
|
||||
tuple[0] = mp_obj_new_int(icolor);
|
||||
tuple[1] = mp_obj_new_int(white);
|
||||
|
||||
tuple[0] = mp_obj_new_int(icolor);
|
||||
tuple[1] = mp_obj_new_int(white);
|
||||
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
pix_tuple[i] = mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
}
|
||||
return mp_obj_new_tuple(cnt, pix_tuple);
|
||||
}
|
||||
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(machine_neopixel_get_obj, machine_neopixel_get);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_neopixel_get_obj, 2, 3, machine_neopixel_get);
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
STATIC mp_obj_t machine_neopixel_brightness(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
||||
@@ -667,6 +694,30 @@ STATIC mp_obj_t machine_neopixel_rainbow(mp_obj_t self_in, mp_obj_t pos_in, mp_o
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(machine_neopixel_rainbow_obj, machine_neopixel_rainbow);
|
||||
|
||||
//-----------------------------------------------------
|
||||
STATIC mp_obj_t machine_neopixel_info(mp_obj_t self_in)
|
||||
{
|
||||
machine_neopixel_obj_t *self = self_in;
|
||||
np_check(self);
|
||||
|
||||
char colorder[5];
|
||||
sprintf(colorder, self->px.color_order);
|
||||
if (self->px.nbits == 24) colorder[3] = '\0';
|
||||
|
||||
mp_obj_t tuple[6];
|
||||
|
||||
tuple[0] = mp_obj_new_int(self->gpio_num);
|
||||
tuple[1] = mp_obj_new_int(self->px.pixel_count);
|
||||
tuple[2] = mp_obj_new_int(self->px.nbits);
|
||||
tuple[3] = mp_obj_new_int(self->channel);
|
||||
tuple[4] = mp_obj_new_int(sizeof(uint32_t) * self->px.pixel_count);
|
||||
tuple[5] = mp_obj_new_str(colorder, strlen(colorder), false);
|
||||
|
||||
return mp_obj_new_tuple(6, tuple);
|
||||
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(machine_neopixel_info_obj, machine_neopixel_info);
|
||||
|
||||
|
||||
//=====================================================================
|
||||
STATIC const mp_rom_map_elem_t machine_neopixel_locals_dict_table[] = {
|
||||
@@ -685,6 +736,7 @@ STATIC const mp_rom_map_elem_t machine_neopixel_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_timings), (mp_obj_t)&machine_neopixel_timings_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_color_order),(mp_obj_t)&machine_neopixel_corder_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rainbow), (mp_obj_t)&machine_neopixel_rainbow_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_info), (mp_obj_t)&machine_neopixel_info_obj },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_BLACK), MP_ROM_INT(0x000000) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_WHITE), MP_ROM_INT(0xFFFFFF) },
|
||||
|
||||
@@ -619,7 +619,7 @@ STATIC const mp_map_elem_t mach_rtc_locals_dict_table[] = {
|
||||
// Constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_EXT1_ANYHIGH), MP_ROM_INT(ESP_EXT1_WAKEUP_ANY_HIGH) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_EXT1_ALLLOW), MP_ROM_INT(ESP_EXT1_WAKEUP_ALL_LOW) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_EXT1_ANYLOW), MP_ROM_INT(EXT1_WAKEUP_ALL_HIGH) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_EXT1_ALLHIGH), MP_ROM_INT(EXT1_WAKEUP_ALL_HIGH) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mach_rtc_locals_dict, mach_rtc_locals_dict_table);
|
||||
|
||||
|
||||
@@ -288,10 +288,33 @@ STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_pri
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uint32_t baudrate;
|
||||
uart_get_baudrate(self->uart_num+1, &baudrate);
|
||||
char lnend[16] = {'\0'};
|
||||
int lnend_idx = 0;
|
||||
for (int i=0; i < strlen((char *)self->lineend); i++) {
|
||||
if (self->lineend[i] == 0) break;
|
||||
if ((self->lineend[i] < 32) || (self->lineend[i] > 126)) {
|
||||
if (self->lineend[i] == '\r') {
|
||||
sprintf(lnend+lnend_idx, "\\r");
|
||||
lnend_idx += 2;
|
||||
}
|
||||
else if (self->lineend[i] == '\n') {
|
||||
sprintf(lnend+lnend_idx, "\\n");
|
||||
lnend_idx += 2;
|
||||
}
|
||||
else {
|
||||
sprintf(lnend+lnend_idx, "\\x%2x", self->lineend[i]);
|
||||
lnend_idx += 4;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sprintf(lnend+lnend_idx, "%c", self->lineend[i]);
|
||||
lnend_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, timeout=%u, buf_size=%u)",
|
||||
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, timeout=%u, buf_size=%u, lineend=b'%s')",
|
||||
self->uart_num+1, baudrate, self->bits, _parity_name[self->parity],
|
||||
self->stop, self->tx, self->rx, self->rts, self->cts, self->timeout, self->buffer_size);
|
||||
self->stop, self->tx, self->rx, self->rts, self->cts, self->timeout, self->buffer_size, lnend);
|
||||
if (self->data_cb) {
|
||||
mp_printf(print, "\n data CB: True, on len: %d", self->data_cb_size);
|
||||
}
|
||||
@@ -418,7 +441,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
|
||||
if (MP_OBJ_IS_STR(args[ARG_lineend].u_obj)) {
|
||||
size_t lnendlen;
|
||||
const char *lnend = mp_obj_str_get_data(args[ARG_lineend].u_obj, &lnendlen);
|
||||
if ((lnend) && (lnendlen > 0) && (lnendlen > 0)) sprintf((char *)self->lineend, "%s", lnend);
|
||||
if ((lnend) && (lnendlen > 0) && (lnendlen < 3)) sprintf((char *)self->lineend, "%s", lnend);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,12 +516,14 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_val_t kargs[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args-1, args+1, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, kargs);
|
||||
|
||||
// Set buffer size
|
||||
int bufsize = kargs[ARG_buffer_size].u_int;
|
||||
if (bufsize < 512) bufsize = 512;
|
||||
if (bufsize > 8192) bufsize = 8192;
|
||||
self->buffer_size = bufsize;
|
||||
|
||||
if (uart_buf[self->uart_num] == NULL) {
|
||||
// First time, create ring buffer
|
||||
uart_ringbuf_alloc(self->uart_num, bufsize);
|
||||
if (uart_buf[self->uart_num] == NULL) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%d) Error allocating ring buffer", uart_num));
|
||||
|
||||
@@ -1450,6 +1450,39 @@ STATIC mp_obj_t display_tft_send_cmd_data(mp_obj_t self_in, mp_obj_t cmd_in, mp_
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(display_tft_send_cmd_data_obj, display_tft_send_cmd_data);
|
||||
|
||||
//--------------------------------------------------
|
||||
STATIC mp_obj_t display_tft_get_bg(mp_obj_t self_in)
|
||||
{
|
||||
int icolor = (int)((_bg.r << 16) | (_bg.g << 8) | _bg.b);
|
||||
return mp_obj_new_int(icolor);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(display_tft_get_bg_obj, display_tft_get_bg);
|
||||
|
||||
//--------------------------------------------------
|
||||
STATIC mp_obj_t display_tft_get_fg(mp_obj_t self_in)
|
||||
{
|
||||
int icolor = (int)((_fg.r << 16) | (_fg.g << 8) | _fg.b);
|
||||
return mp_obj_new_int(icolor);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(display_tft_get_fg_obj, display_tft_get_fg);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
STATIC mp_obj_t display_tft_set_bg(mp_obj_t self_in, mp_obj_t color_in)
|
||||
{
|
||||
color_t color = intToColor(mp_obj_get_int(color_in));
|
||||
_bg = color;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(display_tft_set_bg_obj, display_tft_set_bg);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
STATIC mp_obj_t display_tft_set_fg(mp_obj_t self_in, mp_obj_t color_in)
|
||||
{
|
||||
color_t color = intToColor(mp_obj_get_int(color_in));
|
||||
_fg = color;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(display_tft_set_fg_obj, display_tft_set_fg);
|
||||
|
||||
|
||||
//================================================================
|
||||
@@ -1491,6 +1524,10 @@ STATIC const mp_rom_map_elem_t display_tft_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_getCalib), MP_ROM_PTR(&display_tft_getCalib_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&display_tft_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getTouchType), MP_ROM_PTR(&display_tft_touch_type_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_fg), MP_ROM_PTR(&display_tft_get_fg_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_bg), MP_ROM_PTR(&display_tft_get_bg_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_fg), MP_ROM_PTR(&display_tft_set_fg_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_bg), MP_ROM_PTR(&display_tft_set_bg_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_tft_setspeed), MP_ROM_PTR(&display_tft_set_speed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_tft_select), MP_ROM_PTR(&display_tft_select_obj) },
|
||||
|
||||
@@ -974,7 +974,7 @@ STATIC mp_obj_t mod_network_startFtp(mp_uint_t n_args, const mp_obj_t *pos_args,
|
||||
wifi_mode_t wifi_mode;
|
||||
esp_wifi_get_mode(&wifi_mode);
|
||||
if ((wifi_mode != WIFI_MODE_STA) && (wifi_mode != WIFI_MODE_AP)) {
|
||||
ESP_LOGE("[Ftp]", "Invalif WiFi mode\n");
|
||||
ESP_LOGE("[Ftp]", "Invalid WiFi mode\n");
|
||||
return mp_const_false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.23"
|
||||
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.24"
|
||||
#define MICROPY_GIT_HASH "g77eae33a"
|
||||
#define MICROPY_BUILD_DATE "2017-03-15"
|
||||
#define MICROPY_BUILD_DATE "2017-03-16"
|
||||
#define MICROPY_VERSION_MAJOR (3)
|
||||
#define MICROPY_VERSION_MINOR (1)
|
||||
#define MICROPY_VERSION_MICRO (22)
|
||||
#define MICROPY_VERSION_STRING "3.1.23"
|
||||
#define MICROPY_VERSION_MICRO (24)
|
||||
#define MICROPY_VERSION_STRING "3.1.24"
|
||||
|
||||
Reference in New Issue
Block a user