Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Select Git revision
Loading items
Show changes
Showing
with 821 additions and 190 deletions
......@@ -3,38 +3,40 @@
******************************************************************************/
/***** Includes *****/
#include "mxc_config.h"
#include "led.h"
#include "bhy_uc_driver.h"
#include "board.h"
#include "tmr_utils.h"
#include "display.h"
#include "gfx.h"
#include "gpio.h"
#include "i2c.h"
#include "led.h"
#include "mxc_config.h"
#include "pmic.h"
#include "rtc.h"
#include "spi.h"
#include "gpio.h"
#include "bhy_uc_driver.h"
#include "pmic.h"
#include "GUI_DEV/GUI_Paint.h"
#include "tmr_utils.h"
#include "card10.h"
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M_PI 3.1415
/***** Definitions *****/
/* should be greater or equal to 69 bytes, page size (50) + maximum packet size(18) + 1 */
/* should be greater or equal to 69 bytes, page size (50) + maximum packet
* size(18) + 1 */
#define FIFO_SIZE 300
#define ROTATION_VECTOR_SAMPLE_RATE 10
#define MAX_PACKET_LENGTH 18
#define OUT_BUFFER_SIZE 60
/***** Globals *****/
char out_buffer[OUT_BUFFER_SIZE] = " W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
char out_buffer[OUT_BUFFER_SIZE] =
" W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
uint8_t fifo[FIFO_SIZE];
void draw_arrow(int angle, int color)
......@@ -48,7 +50,7 @@ void draw_arrow(int angle, int color)
int x2 = x1 - sin * 30;
int y2 = y1 - cos * 30;
Paint_DrawLine(x1, y1, x2, y2, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_line(&display_screen, x1, y1, x2, y2, 2, color);
sin = sinf((angle - 140) * 2 * M_PI / 360.);
cos = cosf((angle - 140) * 2 * M_PI / 360.);
......@@ -56,7 +58,7 @@ void draw_arrow(int angle, int color)
int x3 = x2 - sin * 10;
int y3 = y2 - cos * 10;
Paint_DrawLine(x2, y2, x3, y3, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_line(&display_screen, x2, y2, x3, y3, 2, color);
sin = sinf((angle + 140) * 2 * M_PI / 360.);
cos = cosf((angle + 140) * 2 * M_PI / 360.);
......@@ -64,25 +66,29 @@ void draw_arrow(int angle, int color)
int x4 = x2 - sin * 10;
int y4 = y2 - cos * 10;
Paint_DrawLine(x2, y2, x4, y4, color, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
gfx_line(&display_screen, x2, y2, x4, y4, 2, color);
}
/***** Functions *****/
static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static void sensors_callback_orientation(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
static int prev = -1;
printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n",
sensor_data->data_vector.x * 360 / 32768,
sensor_data->data_vector.y * 360 / 32768,
sensor_data->data_vector.z * 360 / 32768,
sensor_data->data_vector.status
);
sensor_data->data_vector.status);
int angle = sensor_data->data_vector.x * 360 / 32768;
if (angle != prev) {
Paint_Clear(BLACK);
int colors[] = {RED, YELLOW, YELLOW, GREEN};
gfx_clear(&display_screen);
int colors[] = { gfx_color(&display_screen, RED),
gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, GREEN) };
int color = colors[sensor_data->data_vector.status];
draw_arrow(sensor_data->data_vector.x * 360 / 32768, color);
......@@ -91,45 +97,51 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v
// Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color);
sprintf(buf, "%3d", angle);
Paint_DrawString_EN(0, 30, buf, &Font24, BLACK, color);
Paint_DrawCircle(57,35, 4, color, DRAW_FILL_EMPTY, DOT_PIXEL_1X1);
gfx_puts(
&Font24,
&display_screen,
0,
30,
buf,
color,
gfx_color(&display_screen, BLACK)
);
gfx_circle(&display_screen, 57, 35, 4, 2, color);
LCD_Update();
gfx_update(&display_screen);
prev = angle;
}
}
static void sensors_callback_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_vector(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_vector.x,
sensor_data->data_vector.y,
sensor_data->data_vector.z,
sensor_data->data_vector.status
);
sensor_data->data_vector.status);
}
static void sensors_callback_vector_uncalib(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_vector_uncalib(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_uncalib_vector.x,
sensor_data->data_uncalib_vector.y,
sensor_data->data_uncalib_vector.z,
sensor_data->data_uncalib_vector.status
);
sensor_data->data_uncalib_vector.status);
}
/*!
* @brief This function is callback function for acquring sensor datas
*
* @param[in] sensor_data
* @param[in] sensor_id
*/
static void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
static __attribute__((unused)) void sensors_callback_rotation_vector(
bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
#if 0
float temp;
uint8_t index;
......@@ -183,8 +195,7 @@ static void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, b
sensor_data->data_quaternion.x,
sensor_data->data_quaternion.y,
sensor_data->data_quaternion.z,
sensor_data->data_quaternion.w
);
sensor_data->data_quaternion.w);
}
// *****************************************************************************
......@@ -210,12 +221,18 @@ int main(void)
}
#endif
//if(bhy_install_sensor_callback(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, sensors_callback_vector_uncalib))
if(bhy_install_sensor_callback(VS_TYPE_ORIENTATION, VS_WAKEUP, sensors_callback_orientation))
{
// if(bhy_install_sensor_callback(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP,
// sensors_callback_vector))
// if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP,
// sensors_callback_vector))
// if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP,
// sensors_callback_vector))
// if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
// VS_WAKEUP, sensors_callback_vector_uncalib))
if (bhy_install_sensor_callback(
VS_TYPE_ORIENTATION,
VS_WAKEUP,
sensors_callback_orientation)) {
printf("Fail to install sensor callback\n");
}
......@@ -227,52 +244,73 @@ int main(void)
}
#endif
/* enables the virtual sensor */
//if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if(bhy_enable_virtual_sensor(VS_TYPE_ORIENTATION, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
{
printf("Fail to enable sensor id=%d\n", VS_TYPE_GEOMAGNETIC_FIELD);
// if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP,
// ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
// if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP,
// ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
// if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP,
// ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
// if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
// VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if (bhy_enable_virtual_sensor(
VS_TYPE_ORIENTATION,
VS_WAKEUP,
ROTATION_VECTOR_SAMPLE_RATE,
0,
VS_FLUSH_NONE,
0,
0)) {
printf("Fail to enable sensor id=%d\n",
VS_TYPE_GEOMAGNETIC_FIELD);
}
while(1)
{
while (1) {
/* wait until the interrupt fires */
/* unless we already know there are bytes remaining in the fifo */
while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining);
bhy_read_fifo(fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining)
;
bhy_read_fifo(
fifo + bytes_left_in_fifo,
FIFO_SIZE - bytes_left_in_fifo,
&bytes_read,
&bytes_remaining
);
bytes_read += bytes_left_in_fifo;
fifoptr = fifo;
packet_type = BHY_DATA_TYPE_PADDING;
do
{
do {
/* this function will call callbacks that are registered */
result = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
result = bhy_parse_next_fifo_packet(
&fifoptr,
&bytes_read,
&fifo_packet,
&packet_type
);
/* prints all the debug packets */
if (packet_type == BHY_DATA_TYPE_DEBUG)
{
bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf);
if (packet_type == BHY_DATA_TYPE_DEBUG) {
bhy_print_debug_packet(
&fifo_packet.data_debug, bhy_printf
);
}
/* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
/* the logic here is that if doing a partial parsing of the fifo, then we
* should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to
* parse an incomplete */
/* packet */
} while ((result == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? MAX_PACKET_LENGTH : 0)));
} while ((result == BHY_SUCCESS) &&
(bytes_read >
(bytes_remaining ? MAX_PACKET_LENGTH : 0)));
bytes_left_in_fifo = 0;
if (bytes_remaining)
{
if (bytes_remaining) {
/* shifts the remaining bytes to the beginning of the buffer */
while (bytes_left_in_fifo < bytes_read)
{
while (bytes_left_in_fifo < bytes_read) {
fifo[bytes_left_in_fifo++] = *(fifoptr++);
}
}
......
file ../../build/hw-tests/ips/ips.elf
source ../../.gdbinit
source ../../init.gdb
file ../../build/hw-tests/ips/ips.elf
......@@ -3,20 +3,21 @@
******************************************************************************/
/***** Includes *****/
#include "tmr_utils.h"
#include "gpio.h"
#include "GUI_DEV/GUI_Paint.h"
#include "DEV_Config.h"
#include "Fonts/fonts.h"
#include "display.h"
#include "gfx.h"
#include "gpio.h"
#include "image/image.h"
#include "tmr.h"
#include "tmr_utils.h"
#include "card10.h"
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
// *****************************************************************************
int main(void)
{
......@@ -25,17 +26,37 @@ int main(void)
card10_init();
card10_diag();
Paint_DrawString_EN(0, 0, "123", &Font24, 0x000f, 0xfff0);
Paint_DrawString_EN(0, 23, "ABC", &Font24, BLUE, CYAN);
Paint_DrawString_CN(20,42, "΢ѩµç×Ó", &Font24CN, WHITE, RED);
Paint_DrawRectangle(70, 10, 100, 40, RED,DRAW_FILL_EMPTY, DOT_PIXEL_2X2 );
Paint_DrawLine(70, 10, 100, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
Paint_DrawLine(100, 10, 70, 40, MAGENTA, LINE_STYLE_SOLID, DOT_PIXEL_2X2);
Paint_DrawCircle(85,25, 22, GREEN, DRAW_FILL_EMPTY, DOT_PIXEL_2X2);
Paint_DrawImage(gImage_40X40,120, 0,40, 40);
Paint_DrawImage(gImage_160X80,0, 0, 160, 80);
LCD_Update();
Color red = gfx_color(&display_screen, RED);
Color green = gfx_color(&display_screen, GREEN);
Color yellow = gfx_color(&display_screen, YELLOW);
gfx_puts(&Font24, &display_screen, 0, 0, "123", 0x000f, 0xfff8);
gfx_puts(&Font24, &display_screen, 23, 0, "ABC", 0x000f, 0xfff8);
gfx_rectangle(&display_screen, 70, 10, 100, 40, 2, red);
gfx_line(&display_screen, 70, 10, 100, 40, 2, green);
gfx_line(&display_screen, 100, 10, 70, 40, 2, yellow);
gfx_circle(&display_screen, 85, 25, 22, 2, green);
gfx_copy_region(
&display_screen,
120,
0,
40,
40,
GFX_RGB565,
(const void *)(gImage_40X40)
);
gfx_copy_region(
&display_screen,
0,
0,
160,
80,
GFX_RGB565,
(const void *)(gImage_160X80)
);
gfx_update(&display_screen);
DEV_Delay_ms(3000);
while (1) {
......
subdir('api-demo/')
# Disabled due to meson bug in older version
# subdir('api-demo/')
subdir('bmatest/')
subdir('bmetest/')
subdir('dual-core/')
subdir('ecgtest/')
subdir('hello-freertos/')
# Disabled due to meson bug in older version
# subdir('hello-freertos/')
subdir('hello-world/')
subdir('imutest/')
subdir('ips/')
subdir('bootloader-update/')
# Disabled due to meson bug in older version
# subdir('upy-minimal/')
source ../../init.gdb
file ../../build/hw-tests/upy-minimal/upy-minimal.elf
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "py/mperrno.h"
#include "lib/utils/pyexec.h"
#include "leds.h"
static char *stack_top;
#if MICROPY_ENABLE_GC
static char heap[4096];
#endif
int mp_hal_stdin_rx_chr(void);
int main(int argc, char **argv)
{
int stack_dummy;
stack_top = (char *)&stack_dummy;
leds_init();
#if MICROPY_ENABLE_GC
gc_init(heap, heap + sizeof(heap));
#endif
mp_init();
pyexec_friendly_repl();
mp_deinit();
return 0;
}
void gc_collect(void)
{
// WARNING: This gc_collect implementation doesn't try to get root
// pointers from CPU registers, and thus may function incorrectly.
void *dummy;
gc_collect_start();
gc_collect_root(
&dummy,
((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t)
);
gc_collect_end();
gc_dump_info();
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename)
{
mp_raise_OSError(MP_ENOENT);
}
mp_import_stat_t mp_import_stat(const char *path)
{
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
{
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
void nlr_jump_fail(void *val)
{
while (1)
;
}
void NORETURN __fatal_error(const char *msg)
{
while (1)
;
}
#ifndef NDEBUG
void MP_WEAK
__assert_func(const char *file, int line, const char *func, const char *expr)
{
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
__fatal_error("Assertion failed");
}
#endif
name = 'upy-minimal'
modsrc = files(
'modules/buzzer.c',
'modules/leds.c',
'modules/utime.c',
)
#################################
# MicroPython Generated Headers #
#################################
version_h = custom_target(
'mpversion-upymin.h',
output: 'mpversion.h',
command: [micropython_gen_version, '@OUTPUT@'],
)
modules_h = custom_target(
'moduledefs-upymin.h',
output: 'moduledefs.h',
input: [micropython_sources, modsrc],
command: [micropython_gen_modules, '@OUTPUT@', '@INPUT@'],
)
qstr_h = custom_target(
'qstrdefs.generated-upymin.h',
output: 'qstrdefs.generated.h',
input: ['modules/qstrdefs.h', micropython_sources],
depends: [modules_h, version_h],
command: [micropython_gen_qstr, meson.current_source_dir(), '@OUTPUT@', '@INPUT@'],
)
###################
# MicroPython Lib #
###################
upy = static_library(
'micropython',
micropython_sources,
micropython_additional_sources,
modules_h,
qstr_h,
version_h,
include_directories: micropython_includes,
)
executable(
name + '.elf',
'main.c',
'uart.c',
'systick.c',
modsrc,
qstr_h,
include_directories: micropython_includes,
dependencies: [libcard10, max32665_startup],
link_whole: [max32665_startup_lib, board_card10_lib],
link_with: upy,
link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
],
)
#include "py/obj.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include <stdio.h>
#include "gpio.h"
static const gpio_cfg_t motor_pin = {
PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE
};
STATIC mp_obj_t buzzer_set(mp_obj_t state_obj)
{
if (state_obj == mp_const_true) {
printf("Buzzer ON!\n");
GPIO_OutSet(&motor_pin);
} else if (state_obj == mp_const_false) {
printf("Buzzer OFF!\n");
GPIO_OutClr(&motor_pin);
} else {
mp_raise_TypeError("expected bool");
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(buzzer_set_obj, buzzer_set);
// Define all properties of the example module.
// Table entries are key/value pairs of the attribute name (a string)
// and the MicroPython object reference.
// All identifiers and strings are written as MP_QSTR_xxx and will be
// optimized to word-sized integers by the build system (interned strings).
STATIC const mp_rom_map_elem_t buzzer_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buzzer) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&buzzer_set_obj) },
};
STATIC MP_DEFINE_CONST_DICT(buzzer_module_globals, buzzer_module_globals_table);
// Define module object.
const mp_obj_module_t buzzer_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&buzzer_module_globals,
};
// Register the module to make it available in Python
MP_REGISTER_MODULE(MP_QSTR_buzzer, buzzer_module, MODULE_BUZZER_ENABLED);
#include "py/obj.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include <stdio.h>
STATIC mp_obj_t mp_leds_set(size_t n_args, const mp_obj_t *args)
{
assert(n_args == 4);
int led = mp_obj_get_int(args[0]);
int r = mp_obj_get_int(args[1]);
int g = mp_obj_get_int(args[2]);
int b = mp_obj_get_int(args[3]);
if ((0 > led || 256 < led) && (0 > r || 256 < r) &&
(0 > g || 256 < g) && (0 > b || 256 < b)) {
mp_raise_ValueError("out of bounds");
}
printf("Set %u to (%x %x %x)\n", led, r, g, b);
leds_set(led, r, g, b);
leds_update();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(leds_set_obj, 4, 4, mp_leds_set);
STATIC mp_obj_t mp_leds_set_dim(mp_obj_t led_obj, mp_obj_t dim_obj)
{
int led = mp_obj_get_int(led_obj);
int dim = mp_obj_get_int(dim_obj);
if ((0 > led || 256 < led) && (0 > dim || 256 < dim)) {
mp_raise_ValueError("out of bounds");
}
leds_set_dim(led, dim);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(leds_set_dim_obj, mp_leds_set_dim);
// Define all properties of the example module.
// Table entries are key/value pairs of the attribute name (a string)
// and the MicroPython object reference.
// All identifiers and strings are written as MP_QSTR_xxx and will be
// optimized to word-sized integers by the build system (interned strings).
STATIC const mp_rom_map_elem_t leds_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_leds) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&leds_set_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_dim), MP_ROM_PTR(&leds_set_dim_obj) },
};
STATIC MP_DEFINE_CONST_DICT(leds_module_globals, leds_module_globals_table);
// Define module object.
const mp_obj_module_t leds_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&leds_module_globals,
};
// Register the module to make it available in Python
MP_REGISTER_MODULE(MP_QSTR_leds, leds_module, MODULE_LEDS_ENABLED);
#include "py/mpconfig.h"
/* buzzer */
Q(buzzer)
/* leds */
Q(leds)
Q(set_dim)
/* utime */
Q(utime)
Q(sleep)
Q(sleep_ms)
Q(sleep_us)
Q(ticks_ms)
Q(ticks_us)
Q(ticks_cpu)
Q(ticks_add)
Q(ticks_diff)
#include <stdio.h>
#include <string.h>
#include "py/runtime.h"
#include "py/smallint.h"
#include "py/obj.h"
#include "lib/timeutils/timeutils.h"
#include "extmod/utime_mphal.h"
STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_diff),
MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
const mp_obj_module_t mp_module_utime = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&time_module_globals,
};
// Register the module to make it available in Python
MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_utime, MODULE_UTIME_ENABLED);
#include <stdint.h>
// options to control how MicroPython is built
// You can disable the built-in MicroPython compiler by setting the following
// config option to 0. If you do this then you won't get a REPL prompt, but you
// will still be able to execute pre-compiled scripts, compiled with mpy-cross.
#define MICROPY_ENABLE_COMPILER (1)
#define MICROPY_QSTR_BYTES_IN_HASH (1)
// #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
#define MICROPY_ALLOC_PATH_MAX (256)
#define MICROPY_ALLOC_PARSE_CHUNK_INIT (16)
#define MICROPY_EMIT_X64 (0)
#define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0)
#define MICROPY_COMP_MODULE_CONST (0)
#define MICROPY_COMP_CONST (0)
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0)
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
#define MICROPY_MEM_STATS (0)
#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_ENABLE_GC (1)
#define MICROPY_GC_ALLOC_THRESHOLD (0)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_HELPER_LEXER_UNIX (0)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_ENABLE_DOC_STRING (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
#define MICROPY_PY_ASYNC_AWAIT (0)
#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
#define MICROPY_PY_BUILTINS_DICT_FROMKEYS (1)
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
#define MICROPY_PY_BUILTINS_ENUMERATE (1)
#define MICROPY_PY_BUILTINS_FILTER (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_REVERSED (1)
#define MICROPY_PY_BUILTINS_SET (1)
#define MICROPY_PY_BUILTINS_SLICE (1)
#define MICROPY_PY_BUILTINS_PROPERTY (1)
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
#define MICROPY_PY_BUILTINS_STR_COUNT (1)
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (0)
#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
#define MICROPY_PY___FILE__ (0)
#define MICROPY_PY_GC (0)
#define MICROPY_PY_ARRAY (1)
#define MICROPY_PY_ATTRTUPLE (1)
#define MICROPY_PY_COLLECTIONS (1)
#define MICROPY_PY_MATH (1)
#define MICROPY_PY_CMATH (1)
#define MICROPY_PY_IO (1)
#define MICROPY_PY_STRUCT (1)
#define MICROPY_PY_SYS (1)
#define MICROPY_MODULE_FROZEN_MPY (0)
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MODULE_BUZZER_ENABLED (1)
#define MODULE_UTIME_ENABLED (1)
#define MODULE_LEDS_ENABLED (1)
// type definitions for the specific machine
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
// This port is intended to be 32-bit, but unfortunately, int32_t for
// different targets may be defined in different ways - either as int
// or as long. This requires different printf formatting specifiers
// to print such value. So, we avoid int32_t and use int directly.
#define UINT_FMT "%u"
#define INT_FMT "%d"
typedef int mp_int_t; // must be pointer size
typedef unsigned mp_uint_t; // must be pointer size
typedef long mp_off_t;
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
#define MICROPY_HW_BOARD_NAME "card10"
#define MICROPY_HW_MCU_NAME "max32665"
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8];
#pragma once
void mp_hal_set_interrupt_char(char c);
#include "py/mpconfig.h"
#include "mxc_delay.h"
void mp_hal_delay_ms(mp_uint_t ms)
{
mxc_delay(ms * 1000); // TODO check return value
}
void mp_hal_delay_us(mp_uint_t us)
{
mxc_delay(us); // TODO check return value
}
mp_uint_t mp_hal_ticks_ms(void)
{
return 0;
}
mp_uint_t mp_hal_ticks_us(void)
{
return 0;
}
mp_uint_t mp_hal_ticks_cpu(void)
{
return 0;
}
#include <unistd.h>
#include "py/mpconfig.h"
#include "uart.h"
/*
* Core UART functions to implement for a port
*/
extern mxc_uart_regs_t *ConsoleUart;
// Receive single character
int mp_hal_stdin_rx_chr(void)
{
return UART_ReadByte(ConsoleUart);
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
{
UART_Write(ConsoleUart, (uint8_t *)str, len);
}
void mp_hal_set_interrupt_char(char c)
{
return;
}
target remote localhost:3333
define reset
mon mww 0x40000004 0x80000000
end
# usage: task_backtrace <tskTCB*>
define task_backtrace
set $taskbt_task_ptr = $arg0
set $taskbt_stack_ptr = $taskbt_task_ptr->pxTopOfStack
set $taskbt_frame_offset = 9
if ((*(uint32_t*)($taskbt_stack_ptr + 8)) & 0x10 == 0)
echo FPU is on\n
set $taskbt_frame_offset += 16
else
echo FPU is off\n
end
set $taskbt_reg_lr = $lr
set $taskbt_reg_pc = $pc
set $taskbt_reg_sp = $sp
set $lr = *($taskbt_stack_ptr + $taskbt_frame_offset + 5)
set $pc = *($taskbt_stack_ptr + $taskbt_frame_offset + 6)
set $sp = $taskbt_stack_ptr + $taskbt_frame_offset + 8
bt
set $lr = $taskbt_reg_lr
set $pc = $taskbt_reg_pc
set $sp = $taskbt_reg_sp
end
alias tbt = task_backtrace
blinky
======
It works! Blink it!
This is a battery-hungry l0dable that shows you how to blink some LEDs while burning CPU time and battery.
#include "epicardium.h"
#include <math.h>
#include <stdio.h>
int levels[11] = { 0 };
int levels_display[11] = { 0 };
void fade()
{
for (int i = 0; i < 11; i++) {
int level = levels[i];
if (levels_display[i] > 0) {
epic_leds_set(i, level, 0, 0);
if (level == 0) {
levels_display[i] = 0;
}
}
if (levels[i] > 0) {
levels[i]--;
}
}
}
/*
* main() is called when l0dable is loaded and executed.
*
* When main() returns, card10 goes back to the menu. A non-zero return value
* can be used to signal some kind of failure during l0dable execution.
*/
int main(void)
{
printf("Hello from blinky!\n");
epic_leds_dim_top(6);
// l0dables are running on a separate, exclusive-to-l0dables core.
// Busy-waiting will not block the main operating system on core0 from
// running - but it will drain batteries.
for (;;) {
for (int i = 0; i < 11; i++) {
levels[i] = 128;
levels_display[i] = 1;
for (int j = 0; j < 32; j++) {
fade();
}
}
for (int i = 9; i > 0; i--) {
levels[i] = 128;
levels_display[i] = 1;
for (int j = 0; j < 32; j++) {
fade();
}
}
}
}
name = 'blinky'
elf = executable(
name + '.elf',
'main.c',
build_by_default: true,
dependencies: [l0dable_startup, api_caller],
link_whole: [l0dable_startup_lib],
link_args: [
'-Wl,-Map=' + meson.current_build_dir() + '/' + name + '.map',
],
pie: true,
)