Skip to content
Snippets Groups Projects
Commit f2539d40 authored by q3k's avatar q3k
Browse files

mpy: remove hardware usermodule

The functionality has been distributed to:

 - kernel (hardware_version, freertos_sleep)
 - uctx (scope)
 - sys_buttons (new, low-level button access)
 - sys_display (new, low-level display access)
parent 42b28396
No related branches found
No related tags found
No related merge requests found
Showing
with 300 additions and 263 deletions
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
add_library(usermod_badge23 INTERFACE) add_library(usermod_badge23 INTERFACE)
target_sources(usermod_badge23 INTERFACE target_sources(usermod_badge23 INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mp_hardware.c ${CMAKE_CURRENT_LIST_DIR}/mp_sys_buttons.c
${CMAKE_CURRENT_LIST_DIR}/mp_leds.c ${CMAKE_CURRENT_LIST_DIR}/mp_leds.c
${CMAKE_CURRENT_LIST_DIR}/mp_audio.c ${CMAKE_CURRENT_LIST_DIR}/mp_audio.c
${CMAKE_CURRENT_LIST_DIR}/mp_sys_bl00mbox.c ${CMAKE_CURRENT_LIST_DIR}/mp_sys_bl00mbox.c
...@@ -14,6 +14,7 @@ target_sources(usermod_badge23 INTERFACE ...@@ -14,6 +14,7 @@ target_sources(usermod_badge23 INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mp_kernel.c ${CMAKE_CURRENT_LIST_DIR}/mp_kernel.c
${CMAKE_CURRENT_LIST_DIR}/mp_uctx.c ${CMAKE_CURRENT_LIST_DIR}/mp_uctx.c
${CMAKE_CURRENT_LIST_DIR}/mp_captouch.c ${CMAKE_CURRENT_LIST_DIR}/mp_captouch.c
${CMAKE_CURRENT_LIST_DIR}/mp_sys_display.c
) )
target_include_directories(usermod_badge23 INTERFACE target_include_directories(usermod_badge23 INTERFACE
......
// probably doesn't need all of these idk
#include <stdio.h>
#include <string.h>
#include "extmod/virtpin.h"
#include "machine_rtc.h"
#include "modmachine.h"
#include "mphalport.h"
#include "py/builtin.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "flow3r_bsp.h"
#include "st3m_console.h"
#include "st3m_gfx.h"
#include "st3m_io.h"
#include "st3m_scope.h"
#include "st3m_usb.h"
// clang-format off
#include "ctx_config.h"
#include "ctx.h"
// clang-format on
mp_obj_t mp_ctx_from_ctx(Ctx *ctx);
STATIC mp_obj_t mp_display_set_backlight(mp_obj_t percent_in) {
uint8_t percent = mp_obj_get_int(percent_in);
flow3r_bsp_display_set_backlight(percent);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_display_set_backlight_obj,
mp_display_set_backlight);
STATIC mp_obj_t mp_left_button_get() {
return mp_obj_new_int(st3m_io_left_button_get());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_left_button_get_obj, mp_left_button_get);
STATIC mp_obj_t mp_right_button_get() {
return mp_obj_new_int(st3m_io_right_button_get());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_right_button_get_obj, mp_right_button_get);
STATIC mp_obj_t mp_version(void) {
mp_obj_t str =
mp_obj_new_str(flow3r_bsp_hw_name, strlen(flow3r_bsp_hw_name));
return str;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_version_obj, mp_version);
static st3m_ctx_desc_t *gfx_last_desc = NULL;
STATIC mp_obj_t mp_get_ctx(void) {
if (gfx_last_desc == NULL) {
gfx_last_desc = st3m_gfx_drawctx_free_get(0);
if (gfx_last_desc == NULL) {
return mp_const_none;
}
}
mp_obj_t mp_ctx = mp_ctx_from_ctx(gfx_last_desc->ctx);
return mp_ctx;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_get_ctx_obj, mp_get_ctx);
STATIC mp_obj_t mp_freertos_sleep(mp_obj_t ms_in) {
uint32_t ms = mp_obj_get_int(ms_in);
MP_THREAD_GIL_EXIT();
vTaskDelay(ms / portTICK_PERIOD_MS);
MP_THREAD_GIL_ENTER();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_freertos_sleep_obj, mp_freertos_sleep);
STATIC mp_obj_t mp_display_update(mp_obj_t in_ctx) {
// TODO(q3k): check in_ctx? Or just drop from API?
if (gfx_last_desc != NULL) {
st3m_gfx_drawctx_pipe_put(gfx_last_desc);
gfx_last_desc = NULL;
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_display_update_obj, mp_display_update);
STATIC mp_obj_t mp_display_pipe_full(void) {
if (st3m_gfx_drawctx_pipe_full()) {
return mp_const_true;
}
return mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_display_pipe_full_obj,
mp_display_pipe_full);
STATIC mp_obj_t mp_display_pipe_flush(void) {
st3m_gfx_flush();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_display_pipe_flush_obj,
mp_display_pipe_flush);
STATIC mp_obj_t mp_scope_draw(mp_obj_t ctx_in) {
// TODO(q3k): check in_ctx? Or just drop from API?
if (gfx_last_desc != NULL) {
st3m_scope_draw(gfx_last_desc->ctx);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_scope_draw_obj, mp_scope_draw);
STATIC mp_obj_t mp_i2c_scan(void) {
flow3r_bsp_i2c_scan_result_t scan;
flow3r_bsp_i2c_scan(&scan);
mp_obj_t res = mp_obj_new_list(0, NULL);
for (int i = 0; i < 127; i++) {
size_t ix = i / 32;
size_t offs = i % 32;
if (scan.res[ix] & (1 << offs)) {
mp_obj_list_append(res, mp_obj_new_int_from_uint(i));
}
}
return res;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_i2c_scan_obj, mp_i2c_scan);
STATIC mp_obj_t mp_usb_connected(void) {
static int64_t last_check = 0;
static bool value = false;
int64_t now = esp_timer_get_time();
if (last_check == 0) {
last_check = now;
value = st3m_usb_connected();
}
if ((now - last_check) > 10000) {
value = st3m_usb_connected();
last_check = now;
}
return mp_obj_new_bool(value);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_usb_connected_obj, mp_usb_connected);
STATIC mp_obj_t mp_usb_console_active(void) {
static int64_t last_check = 0;
static bool value = false;
int64_t now = esp_timer_get_time();
if (last_check == 0) {
last_check = now;
value = st3m_console_active();
}
if ((now - last_check) > 10000) {
value = st3m_console_active();
last_check = now;
}
return mp_obj_new_bool(value);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_usb_console_active_obj,
mp_usb_console_active);
STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hardware) },
{ MP_ROM_QSTR(MP_QSTR_left_button_get),
MP_ROM_PTR(&mp_left_button_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_right_button_get),
MP_ROM_PTR(&mp_right_button_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_update), MP_ROM_PTR(&mp_display_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_freertos_sleep), MP_ROM_PTR(&mp_freertos_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_pipe_full),
MP_ROM_PTR(&mp_display_pipe_full_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_pipe_flush),
MP_ROM_PTR(&mp_display_pipe_flush_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_set_backlight),
MP_ROM_PTR(&mp_display_set_backlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&mp_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_ctx), MP_ROM_PTR(&mp_get_ctx_obj) },
{ MP_ROM_QSTR(MP_QSTR_usb_connected), MP_ROM_PTR(&mp_usb_connected_obj) },
{ MP_ROM_QSTR(MP_QSTR_usb_console_active),
MP_ROM_PTR(&mp_usb_console_active_obj) },
{ MP_ROM_QSTR(MP_QSTR_i2c_scan), MP_ROM_PTR(&mp_i2c_scan_obj) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_PRESSED_LEFT), MP_ROM_INT(st3m_tripos_left) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_PRESSED_RIGHT),
MP_ROM_INT(st3m_tripos_right) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_PRESSED_DOWN), MP_ROM_INT(st3m_tripos_mid) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_NOT_PRESSED), MP_ROM_INT(st3m_tripos_none) },
{ MP_ROM_QSTR(MP_QSTR_scope_draw), MP_ROM_PTR(&mp_scope_draw_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_hardware_globals,
mp_module_hardware_globals_table);
const mp_obj_module_t mp_module_hardware = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_hardware_globals,
};
MP_REGISTER_MODULE(MP_QSTR_hardware, mp_module_hardware);
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "flow3r_bsp.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "st3m_console.h"
#include "st3m_usb.h"
#include "st3m_version.h" #include "st3m_version.h"
#if (configUSE_TRACE_FACILITY != 1) #if (configUSE_TRACE_FACILITY != 1)
...@@ -299,12 +302,89 @@ STATIC mp_obj_t mp_firmware_version(void) { ...@@ -299,12 +302,89 @@ STATIC mp_obj_t mp_firmware_version(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_firmware_version_obj, mp_firmware_version); STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_firmware_version_obj, mp_firmware_version);
STATIC mp_obj_t mp_hardware_version(void) {
mp_obj_t str =
mp_obj_new_str(flow3r_bsp_hw_name, strlen(flow3r_bsp_hw_name));
return str;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_hardware_version_obj, mp_hardware_version);
STATIC mp_obj_t mp_freertos_sleep(mp_obj_t ms_in) {
uint32_t ms = mp_obj_get_int(ms_in);
MP_THREAD_GIL_EXIT();
vTaskDelay(ms / portTICK_PERIOD_MS);
MP_THREAD_GIL_ENTER();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_freertos_sleep_obj, mp_freertos_sleep);
STATIC mp_obj_t mp_usb_connected(void) {
static int64_t last_check = 0;
static bool value = false;
int64_t now = esp_timer_get_time();
if (last_check == 0) {
last_check = now;
value = st3m_usb_connected();
}
if ((now - last_check) > 10000) {
value = st3m_usb_connected();
last_check = now;
}
return mp_obj_new_bool(value);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_usb_connected_obj, mp_usb_connected);
STATIC mp_obj_t mp_usb_console_active(void) {
static int64_t last_check = 0;
static bool value = false;
int64_t now = esp_timer_get_time();
if (last_check == 0) {
last_check = now;
value = st3m_console_active();
}
if ((now - last_check) > 10000) {
value = st3m_console_active();
last_check = now;
}
return mp_obj_new_bool(value);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_usb_console_active_obj,
mp_usb_console_active);
STATIC mp_obj_t mp_i2c_scan(void) {
flow3r_bsp_i2c_scan_result_t scan;
flow3r_bsp_i2c_scan(&scan);
mp_obj_t res = mp_obj_new_list(0, NULL);
for (int i = 0; i < 127; i++) {
size_t ix = i / 32;
size_t offs = i % 32;
if (scan.res[ix] & (1 << offs)) {
mp_obj_list_append(res, mp_obj_new_int_from_uint(i));
}
}
return res;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_i2c_scan_obj, mp_i2c_scan);
STATIC const mp_rom_map_elem_t globals_table[] = { STATIC const mp_rom_map_elem_t globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_scheduler_snapshot), { MP_ROM_QSTR(MP_QSTR_scheduler_snapshot),
MP_ROM_PTR(&mp_scheduler_snapshot_obj) }, MP_ROM_PTR(&mp_scheduler_snapshot_obj) },
{ MP_ROM_QSTR(MP_QSTR_heap_stats), MP_ROM_PTR(&mp_heap_stats_obj) }, { MP_ROM_QSTR(MP_QSTR_heap_stats), MP_ROM_PTR(&mp_heap_stats_obj) },
{ MP_ROM_QSTR(MP_QSTR_firmware_version), { MP_ROM_QSTR(MP_QSTR_firmware_version),
MP_ROM_PTR(&mp_firmware_version_obj) }, MP_ROM_PTR(&mp_firmware_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_hardware_version),
MP_ROM_PTR(&mp_hardware_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_freertos_sleep), MP_ROM_PTR(&mp_freertos_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_usb_connected), MP_ROM_PTR(&mp_usb_connected_obj) },
{ MP_ROM_QSTR(MP_QSTR_usb_console_active),
MP_ROM_PTR(&mp_usb_console_active_obj) },
{ MP_ROM_QSTR(MP_QSTR_i2c_scan), MP_ROM_PTR(&mp_i2c_scan_obj) },
{ MP_ROM_QSTR(MP_QSTR_RUNNING), MP_ROM_INT(eRunning) }, { MP_ROM_QSTR(MP_QSTR_RUNNING), MP_ROM_INT(eRunning) },
{ MP_ROM_QSTR(MP_QSTR_READY), MP_ROM_INT(eReady) }, { MP_ROM_QSTR(MP_QSTR_READY), MP_ROM_INT(eReady) },
......
// probably doesn't need all of these idk
#include <stdio.h>
#include <string.h>
#include "extmod/virtpin.h"
#include "machine_rtc.h"
#include "modmachine.h"
#include "mphalport.h"
#include "py/builtin.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "flow3r_bsp.h"
#include "st3m_console.h"
#include "st3m_gfx.h"
#include "st3m_io.h"
#include "st3m_scope.h"
#include "mp_uctx.h"
STATIC mp_obj_t mp_get_left() {
return mp_obj_new_int(st3m_io_left_button_get());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_get_left_obj, mp_get_left);
STATIC mp_obj_t mp_get_right() {
return mp_obj_new_int(st3m_io_right_button_get());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_get_right_obj, mp_get_right);
STATIC const mp_rom_map_elem_t mp_module_sys_buttons_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_buttons) },
{ MP_ROM_QSTR(MP_QSTR_get_left), MP_ROM_PTR(&mp_get_left_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_right), MP_ROM_PTR(&mp_get_right_obj) },
{ MP_ROM_QSTR(MP_QSTR_PRESSED_LEFT), MP_ROM_INT(st3m_tripos_left) },
{ MP_ROM_QSTR(MP_QSTR_PRESSED_RIGHT), MP_ROM_INT(st3m_tripos_right) },
{ MP_ROM_QSTR(MP_QSTR_PRESSED_DOWN), MP_ROM_INT(st3m_tripos_mid) },
{ MP_ROM_QSTR(MP_QSTR_NOT_PRESSED), MP_ROM_INT(st3m_tripos_none) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_sys_buttons_globals,
mp_module_sys_buttons_globals_table);
const mp_obj_module_t mp_module_sys_buttons = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_sys_buttons_globals,
};
MP_REGISTER_MODULE(MP_QSTR_sys_buttons, mp_module_sys_buttons);
// probably doesn't need all of these idk
#include <stdio.h>
#include <string.h>
#include "extmod/virtpin.h"
#include "machine_rtc.h"
#include "modmachine.h"
#include "mphalport.h"
#include "py/builtin.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "flow3r_bsp.h"
#include "st3m_console.h"
#include "st3m_gfx.h"
#include "st3m_io.h"
#include "st3m_scope.h"
#include "mp_uctx.h"
static st3m_ctx_desc_t *gfx_last_desc = NULL;
STATIC mp_obj_t mp_set_backlight(mp_obj_t percent_in) {
uint8_t percent = mp_obj_get_int(percent_in);
flow3r_bsp_display_set_backlight(percent);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_set_backlight_obj, mp_set_backlight);
STATIC mp_obj_t mp_get_ctx(void) {
if (gfx_last_desc == NULL) {
gfx_last_desc = st3m_gfx_drawctx_free_get(0);
if (gfx_last_desc == NULL) {
return mp_const_none;
}
}
mp_obj_t mp_ctx = mp_ctx_from_ctx(gfx_last_desc->ctx);
return mp_ctx;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_get_ctx_obj, mp_get_ctx);
STATIC mp_obj_t mp_update(mp_obj_t ctx_in) {
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(ctx_in);
if (self->base.type != &mp_ctx_type) {
mp_raise_ValueError("not a ctx");
return mp_const_none;
}
if (gfx_last_desc != NULL) {
if (gfx_last_desc->ctx != self->ctx) {
mp_raise_ValueError(
"not the correct ctx (do not hold on to ctx objects!)");
return mp_const_none;
}
st3m_gfx_drawctx_pipe_put(gfx_last_desc);
gfx_last_desc = NULL;
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_update_obj, mp_update);
STATIC mp_obj_t mp_pipe_full(void) {
if (st3m_gfx_drawctx_pipe_full()) {
return mp_const_true;
}
return mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_pipe_full_obj, mp_pipe_full);
STATIC mp_obj_t mp_pipe_flush(void) {
st3m_gfx_flush();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_pipe_flush_obj, mp_pipe_flush);
STATIC const mp_rom_map_elem_t mp_module_sys_display_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_display) },
{ MP_ROM_QSTR(MP_QSTR_pipe_full), MP_ROM_PTR(&mp_pipe_full_obj) },
{ MP_ROM_QSTR(MP_QSTR_pipe_flush), MP_ROM_PTR(&mp_pipe_flush_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&mp_set_backlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&mp_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_ctx), MP_ROM_PTR(&mp_get_ctx_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_sys_display_globals,
mp_module_sys_display_globals_table);
const mp_obj_module_t mp_module_sys_display = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_sys_display_globals,
};
MP_REGISTER_MODULE(MP_QSTR_sys_display, mp_module_sys_display);
...@@ -4,16 +4,8 @@ ...@@ -4,16 +4,8 @@
#include "py/objarray.h" #include "py/objarray.h"
#include "py/runtime.h" #include "py/runtime.h"
// clang-format off #include "mp_uctx.h"
#include "ctx_config.h" #include "st3m_scope.h"
#include "ctx.h"
// clang-format on
typedef struct _mp_ctx_obj_t {
mp_obj_base_t base;
Ctx *ctx;
mp_obj_t user_data;
} mp_ctx_obj_t;
void gc_collect(void); void gc_collect(void);
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
...@@ -245,6 +237,13 @@ MP_CTX_COMMON_FUN_6F(radial_gradient); ...@@ -245,6 +237,13 @@ MP_CTX_COMMON_FUN_6F(radial_gradient);
MP_CTX_COMMON_FUN_3F(logo); MP_CTX_COMMON_FUN_3F(logo);
static mp_obj_t mp_ctx_scope(mp_obj_t self_in) {
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in);
st3m_scope_draw(self->ctx);
return self_in;
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_ctx_scope_obj, mp_ctx_scope);
static mp_obj_t mp_ctx_key_down(size_t n_args, const mp_obj_t *args) { static mp_obj_t mp_ctx_key_down(size_t n_args, const mp_obj_t *args) {
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_ctx_obj_t *self = MP_OBJ_TO_PTR(args[0]);
ctx_key_down(self->ctx, ctx_key_down(self->ctx,
...@@ -514,8 +513,6 @@ STATIC void generic_method_lookup(mp_obj_t obj, qstr attr, mp_obj_t *dest) { ...@@ -514,8 +513,6 @@ STATIC void generic_method_lookup(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
} }
} }
extern const mp_obj_type_t mp_ctx_type;
#if CTX_TINYVG #if CTX_TINYVG
static mp_obj_t mp_ctx_tinyvg_get_size(mp_obj_t self_in, mp_obj_t buffer_in) { static mp_obj_t mp_ctx_tinyvg_get_size(mp_obj_t self_in, mp_obj_t buffer_in) {
mp_buffer_info_t buffer_info; mp_buffer_info_t buffer_info;
...@@ -857,6 +854,7 @@ static const mp_rom_map_elem_t mp_ctx_locals_dict_table[] = { ...@@ -857,6 +854,7 @@ static const mp_rom_map_elem_t mp_ctx_locals_dict_table[] = {
#endif #endif
#endif #endif
MP_CTX_METHOD(logo), MP_CTX_METHOD(logo),
MP_CTX_METHOD(scope),
// Instance attributes // Instance attributes
MP_CTX_ATTR(x), MP_CTX_ATTR(x),
......
#pragma once
// clang-format off
#include "ctx_config.h"
#include "ctx.h"
// clang-format on
typedef struct _mp_ctx_obj_t {
mp_obj_base_t base;
Ctx *ctx;
mp_obj_t user_data;
} mp_ctx_obj_t;
extern const mp_obj_type_t mp_ctx_type;
mp_obj_t mp_ctx_from_ctx(Ctx *ctx);
\ No newline at end of file
``hardware`` module ``sys_buttons`` module
=================== ======================
.. automodule:: hardware .. automodule:: sys_buttons
:members: :members:
:undoc-members: :undoc-members:
``sys_display`` module
======================
.. automodule:: sys_display
:members:
:undoc-members:
...@@ -80,13 +80,14 @@ Example 1b: React to input ...@@ -80,13 +80,14 @@ Example 1b: React to input
If we want to react to the user, we can use the :py:class:`InputState` which got If we want to react to the user, we can use the :py:class:`InputState` which got
handed to us. In this example we look at the state of the app (by default left) handed to us. In this example we look at the state of the app (by default left)
shoulder button. The values contained in the input state are the same as used shoulder button. The values for buttons contained in the input state are one of
by the :py:mod:`hardware` module. ``InputButtonState.PRESSED_LEFT``, ``PRESSED_RIGHT``, ``PRESSED_DOWN``,
``NOT_PRESSED`` - same values as in the low-level
:py:mod:`sys_buttons`.
.. code-block:: python .. code-block:: python
from st3m.reactor import Responder from st3m.reactor import Responder
from hardware import BUTTON_PRESSED_LEFT, BUTTON_PRESSED_RIGHT, BUTTON_PRESSED_DOWN
import st3m.run import st3m.run
class Example(Responder): class Example(Responder):
...@@ -103,9 +104,9 @@ by the :py:mod:`hardware` module. ...@@ -103,9 +104,9 @@ by the :py:mod:`hardware` module.
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
direction = ins.buttons.app direction = ins.buttons.app
if direction == BUTTON_PRESSED_LEFT: if direction == ins.buttons.PRESSED_LEFT:
self._x -= 1 self._x -= 1
elif direction == BUTTON_PRESSED_RIGHT: elif direction == ins.buttons.PRESSED_RIGHT:
self._x += 1 self._x += 1
...@@ -128,7 +129,6 @@ represents the time which has passed since the last call to `think()`. ...@@ -128,7 +129,6 @@ represents the time which has passed since the last call to `think()`.
.. code-block:: python .. code-block:: python
from st3m.reactor import Responder from st3m.reactor import Responder
from hardware import BUTTON_PRESSED_LEFT, BUTTON_PRESSED_RIGHT, BUTTON_PRESSED_DOWN
import st3m.run import st3m.run
class Example(Responder): class Example(Responder):
...@@ -145,9 +145,9 @@ represents the time which has passed since the last call to `think()`. ...@@ -145,9 +145,9 @@ represents the time which has passed since the last call to `think()`.
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
direction = ins.buttons.app # -1 (left), 1 (right), or 2 (pressed) direction = ins.buttons.app # -1 (left), 1 (right), or 2 (pressed)
if direction == BUTTON_PRESSED_LEFT: if direction == ins.buttons.PRESSED_LEFT:
self._x -= 20 * delta_ms / 1000 self._x -= 20 * delta_ms / 1000
elif direction == BUTTON_PRESSED_RIGHT: elif direction == ins.buttons.PRESSED_RIGHT:
self._x += 40 * delta_ms / 1000 self._x += 40 * delta_ms / 1000
...@@ -213,7 +213,6 @@ a square. ...@@ -213,7 +213,6 @@ a square.
from st3m.input import InputController from st3m.input import InputController
from st3m.utils import tau from st3m.utils import tau
from hardware import BUTTON_PRESSED_LEFT, BUTTON_PRESSED_RIGHT, BUTTON_PRESSED_DOWN
import st3m.run import st3m.run
class Example(Responder): class Example(Responder):
......
...@@ -26,10 +26,11 @@ Welcome to flow3r's documentation! ...@@ -26,10 +26,11 @@ Welcome to flow3r's documentation!
api/audio.rst api/audio.rst
api/badgelink.rst api/badgelink.rst
api/captouch.rst api/captouch.rst
api/hardware.rst
api/kernel.rst api/kernel.rst
api/leds.rst api/leds.rst
api/ctx.rst api/ctx.rst
api/sys_buttons.rst
api/sys_display.rst
Indices and tables Indices and tables
================== ==================
......
...@@ -11,8 +11,6 @@ import cmath ...@@ -11,8 +11,6 @@ import cmath
import math import math
import time import time
import hardware
class Dot: class Dot:
def __init__(self, size: float, imag: float, real: float) -> None: def __init__(self, size: float, imag: float, real: float) -> None:
......
...@@ -3,7 +3,6 @@ import bl00mbox ...@@ -3,7 +3,6 @@ import bl00mbox
blm = bl00mbox.Channel("Harmonic Demo") blm = bl00mbox.Channel("Harmonic Demo")
import leds import leds
import hardware
from st3m.goose import List from st3m.goose import List
from st3m.input import InputState from st3m.input import InputState
...@@ -57,7 +56,7 @@ class HarmonicApp(Application): ...@@ -57,7 +56,7 @@ class HarmonicApp(Application):
ctx.rgb(i, i, i).rectangle(-120, -120, 240, 240).fill() ctx.rgb(i, i, i).rectangle(-120, -120, 240, 240).fill()
ctx.rgb(0, 0, 0) ctx.rgb(0, 0, 0)
hardware.scope_draw(ctx) ctx.scope()
ctx.fill() ctx.fill()
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
......
...@@ -2,7 +2,6 @@ import bl00mbox ...@@ -2,7 +2,6 @@ import bl00mbox
blm = bl00mbox.Channel("Melodic Demo") blm = bl00mbox.Channel("Melodic Demo")
from hardware import *
import captouch import captouch
import leds import leds
...@@ -97,7 +96,7 @@ class MelodicApp(Application): ...@@ -97,7 +96,7 @@ class MelodicApp(Application):
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
ctx.rgb(1, 1, 1).rectangle(-120, -120, 240, 240).fill() ctx.rgb(1, 1, 1).rectangle(-120, -120, 240, 240).fill()
ctx.rgb(0, 0, 0) ctx.rgb(0, 0, 0)
scope_draw(ctx) ctx.scope()
ctx.fill() ctx.fill()
def on_enter(self, vm: Optional[ViewManager]) -> None: def on_enter(self, vm: Optional[ViewManager]) -> None:
......
...@@ -10,7 +10,6 @@ import captouch ...@@ -10,7 +10,6 @@ import captouch
import bl00mbox import bl00mbox
import leds import leds
import hardware
import random import random
chords = [ chords = [
......
import bl00mbox import bl00mbox
import hardware
import captouch import captouch
import leds import leds
......
...@@ -313,3 +313,11 @@ class Context(Protocol): ...@@ -313,3 +313,11 @@ class Context(Protocol):
TOD(q3k): document TOD(q3k): document
""" """
pass pass
def scope(self) -> "Context":
"""
Draw an audio 'oscilloscope'-style visualizer at -120,-120,120,120
bounding box.
Needs to be stroked/filled afterwards.
"""
pass
import time
from ctx import Context
def freertos_sleep(ms: int) -> None: ...
def get_ctx() -> Context: ...
def display_pipe_full() -> bool: ...
def display_pipe_flush() -> None: ...
def display_update(c: Context) -> None: ...
def display_set_backlight(percent: int) -> None: ...
def usb_connected() -> bool: ...
def usb_console_active() -> bool: ...
def version() -> str: ...
def i2c_scan() -> list[int]: ...
def menu_button_get() -> int: ...
def application_button_get() -> int: ...
def left_button_get() -> int: ...
def right_button_get() -> int: ...
def menu_button_set_left(left: int) -> None: ...
def menu_button_get_left() -> int: ...
def scope_draw(ctx: Context) -> None: ...
BUTTON_PRESSED_LEFT: int
BUTTON_PRESSED_RIGHT: int
BUTTON_PRESSED_DOWN: int
BUTTON_NOT_PRESSED: int
...@@ -64,3 +64,10 @@ BLOCKED: int ...@@ -64,3 +64,10 @@ BLOCKED: int
SUSPENDED: int SUSPENDED: int
DELETED: int DELETED: int
INVALID: int INVALID: int
def freertos_sleep(ms: int) -> None: ...
def usb_connected() -> bool: ...
def usb_console_active() -> bool: ...
def hardware_version() -> str: ...
def firmware_version() -> str: ...
def i2c_scan() -> list[int]: ...
def get_left() -> int: ...
def get_right() -> int: ...
PRESSED_LEFT: int
PRESSED_RIGHT: int
PRESSED_DOWN: int
NOT_PRESSED: int
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment