kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Initial setup og GU Micropython
rodzic
5ea389c12a
commit
a25699c73d
|
@ -38,15 +38,6 @@
|
|||
//
|
||||
// .. and back to the start
|
||||
|
||||
constexpr uint32_t ROW_COUNT = 11;
|
||||
constexpr uint32_t BCD_FRAME_COUNT = 14;
|
||||
constexpr uint32_t BCD_FRAME_BYTES = 60;
|
||||
constexpr uint32_t ROW_BYTES = BCD_FRAME_COUNT * BCD_FRAME_BYTES;
|
||||
constexpr uint32_t BITSTREAM_LENGTH = (ROW_COUNT * ROW_BYTES);
|
||||
|
||||
// must be aligned for 32bit dma transfer
|
||||
alignas(4) static uint8_t bitstream[BITSTREAM_LENGTH] = {0};
|
||||
|
||||
static uint16_t r_gamma_lut[256] = {0};
|
||||
static uint16_t g_gamma_lut[256] = {0};
|
||||
static uint16_t b_gamma_lut[256] = {0};
|
||||
|
@ -56,16 +47,24 @@ static uint32_t audio_dma_channel;
|
|||
|
||||
namespace pimoroni {
|
||||
|
||||
GalacticUnicorn* GalacticUnicorn::unicorn = nullptr;
|
||||
|
||||
// once the dma transfer of the scanline is complete we move to the
|
||||
// next scanline (or quit if we're finished)
|
||||
void __isr dma_complete() {
|
||||
if (dma_hw->ints0 & (1u << dma_channel)) {
|
||||
dma_hw->ints0 = (1u << dma_channel); // clear irq flag
|
||||
dma_channel_set_trans_count(dma_channel, BITSTREAM_LENGTH / 4, false);
|
||||
dma_channel_set_read_addr(dma_channel, bitstream, true);
|
||||
void __isr GalacticUnicorn::dma_complete() {
|
||||
if(dma_channel_get_irq0_status(dma_channel) && unicorn != nullptr) {
|
||||
unicorn->next_dma_sequence();
|
||||
}
|
||||
}
|
||||
|
||||
void GalacticUnicorn::next_dma_sequence() {
|
||||
// Clear any interrupt request caused by our channel
|
||||
dma_channel_acknowledge_irq0(dma_channel);
|
||||
|
||||
dma_channel_set_trans_count(dma_channel, BITSTREAM_LENGTH / 4, false);
|
||||
dma_channel_set_read_addr(dma_channel, bitstream, true);
|
||||
}
|
||||
|
||||
GalacticUnicorn::~GalacticUnicorn() {
|
||||
// stop and release the dma channel
|
||||
irq_set_enabled(DMA_IRQ_0, false);
|
||||
|
@ -267,6 +266,8 @@ namespace pimoroni {
|
|||
irq_set_exclusive_handler(DMA_IRQ_0, dma_complete);
|
||||
irq_set_enabled(DMA_IRQ_0, true);
|
||||
|
||||
unicorn = this;
|
||||
|
||||
dma_channel_set_trans_count(dma_channel, BITSTREAM_LENGTH / 4, false);
|
||||
dma_channel_set_read_addr(dma_channel, bitstream, true);
|
||||
|
||||
|
|
|
@ -44,6 +44,13 @@ namespace pimoroni {
|
|||
static const uint8_t SWITCH_BRIGHTNESS_UP = 21;
|
||||
static const uint8_t SWITCH_BRIGHTNESS_DOWN = 26;
|
||||
|
||||
private:
|
||||
static const uint32_t ROW_COUNT = 11;
|
||||
static const uint32_t BCD_FRAME_COUNT = 14;
|
||||
static const uint32_t BCD_FRAME_BYTES = 60;
|
||||
static const uint32_t ROW_BYTES = BCD_FRAME_COUNT * BCD_FRAME_BYTES;
|
||||
static const uint32_t BITSTREAM_LENGTH = (ROW_COUNT * ROW_BYTES);
|
||||
|
||||
private:
|
||||
PIO bitstream_pio = pio0;
|
||||
uint bitstream_sm = 0;
|
||||
|
@ -56,6 +63,11 @@ namespace pimoroni {
|
|||
uint16_t brightness = 256;
|
||||
uint16_t volume = 127;
|
||||
|
||||
// must be aligned for 32bit dma transfer
|
||||
alignas(4) uint8_t bitstream[BITSTREAM_LENGTH] = {0};
|
||||
static GalacticUnicorn* unicorn;
|
||||
static void dma_complete();
|
||||
|
||||
public:
|
||||
~GalacticUnicorn();
|
||||
|
||||
|
@ -85,6 +97,8 @@ namespace pimoroni {
|
|||
|
||||
void play_sample(uint8_t *data, uint32_t length);
|
||||
|
||||
private:
|
||||
void next_dma_sequence();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
#include "galactic_unicorn.h"
|
||||
|
||||
|
||||
/***** Methods *****/
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn___del___obj, GalacticUnicorn___del__);
|
||||
/*MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_clear_obj, GalacticUnicorn_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_update_obj, 1, GalacticUnicorn_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_set_brightness_obj, GalacticUnicorn_set_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_get_brightness_obj, GalacticUnicorn_get_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_adjust_brightness_obj, GalacticUnicorn_adjust_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_set_volume_obj, GalacticUnicorn_set_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_get_volume_obj, GalacticUnicorn_get_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_adjust_volume_obj, GalacticUnicorn_adjust_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_set_pixel_obj, 1, GalacticUnicorn_set_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_light_obj, GalacticUnicorn_light);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_is_pressed_obj, GalacticUnicorn_is_pressed);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_play_sample_obj, 1, GalacticUnicorn_play_sample);*/
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t GalacticUnicorn_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&GalacticUnicorn___del___obj) },
|
||||
/*{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&GalacticUnicorn_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&GalacticUnicorn_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_brightness), MP_ROM_PTR(&GalacticUnicorn_set_brightness_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_brightness), MP_ROM_PTR(&GalacticUnicorn_get_brightness_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_adjust_brightness), MP_ROM_PTR(&GalacticUnicorn_adjust_brightness_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_volume), MP_ROM_PTR(&GalacticUnicorn_set_volume_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_volume), MP_ROM_PTR(&GalacticUnicorn_get_volume_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_adjust_volume), MP_ROM_PTR(&GalacticUnicorn_adjust_volume_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&GalacticUnicorn_set_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_light), MP_ROM_PTR(&GalacticUnicorn_light_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_pressed), MP_ROM_PTR(&GalacticUnicorn_is_pressed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_play_sample), MP_ROM_PTR(&GalacticUnicorn_play_sample_obj) },*/
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(53) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(11) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(GalacticUnicorn_locals_dict, GalacticUnicorn_locals_dict_table);
|
||||
|
||||
/***** Class Definition *****/
|
||||
const mp_obj_type_t GalacticUnicorn_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_GalacticUnicorn,
|
||||
.print = GalacticUnicorn_print,
|
||||
.make_new = GalacticUnicorn_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&GalacticUnicorn_locals_dict,
|
||||
};
|
||||
|
||||
/***** Globals Table *****/
|
||||
STATIC const mp_map_elem_t galactic_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_galactic) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_GalacticUnicorn), (mp_obj_t)&GalacticUnicorn_type },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_galactic_globals, galactic_globals_table);
|
||||
|
||||
/***** Module Definition *****/
|
||||
const mp_obj_module_t galactic_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_galactic_globals,
|
||||
};
|
||||
#if MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_galactic, galactic_user_cmodule, MODULE_GALACTIC_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_galactic, galactic_user_cmodule);
|
||||
#endif
|
|
@ -0,0 +1,141 @@
|
|||
#include "libraries/galactic_unicorn/galactic_unicorn.hpp"
|
||||
#include "micropython/modules/util.hpp"
|
||||
#include <cstdio>
|
||||
#include <cfloat>
|
||||
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern "C" {
|
||||
#include "galactic_unicorn.h"
|
||||
#include "py/builtin.h"
|
||||
|
||||
|
||||
/********** GalacticUnicorn **********/
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _GalacticUnicorn_obj_t {
|
||||
mp_obj_base_t base;
|
||||
GalacticUnicorn* galactic;
|
||||
} _GalacticUnicorn_obj_t;
|
||||
|
||||
|
||||
/***** Print *****/
|
||||
void GalacticUnicorn_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind; //Unused input parameter
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
mp_print_str(print, "GalacticUnicorn()");
|
||||
}
|
||||
|
||||
|
||||
/***** Constructor *****/
|
||||
mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
_GalacticUnicorn_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_pio, ARG_sm, ARG_pins, ARG_common_pin, ARG_direction, ARG_counts_per_rev, ARG_count_microsteps, ARG_freq_divider };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pio, MP_ARG_INT },
|
||||
{ MP_QSTR_sm, MP_ARG_INT }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
int pio_int = args[ARG_pio].u_int;
|
||||
if(pio_int < 0 || pio_int > (int)NUM_PIOS) {
|
||||
mp_raise_ValueError("pio out of range. Expected 0 to 1");
|
||||
}
|
||||
//PIO pio = pio_int == 0 ? pio0 : pio1;
|
||||
|
||||
int sm = args[ARG_sm].u_int;
|
||||
if(sm < 0 || sm > (int)NUM_PIO_STATE_MACHINES) {
|
||||
mp_raise_ValueError("sm out of range. Expected 0 to 3");
|
||||
}
|
||||
|
||||
|
||||
GalacticUnicorn *galactic = m_new_class(GalacticUnicorn);
|
||||
galactic->init();
|
||||
//if(!galactic->init()) {
|
||||
//m_del_class(GalacticUnicorn, galactic);
|
||||
//mp_raise_msg(&mp_type_RuntimeError, "unable to allocate the hardware resources needed to initialise this GalacticUnicorn. Try running `import gc` followed by `gc.collect()` before creating it");
|
||||
//}
|
||||
|
||||
self = m_new_obj_with_finaliser(_GalacticUnicorn_obj_t);
|
||||
self->base.type = &GalacticUnicorn_type;
|
||||
self->galactic = galactic;
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
|
||||
/***** Destructor ******/
|
||||
mp_obj_t GalacticUnicorn___del__(mp_obj_t self_in) {
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
m_del_class(GalacticUnicorn, self->galactic);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
/***** Methods *****/
|
||||
extern mp_obj_t GalacticUnicorn_clear(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
//self->galactic->clear();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_brightness(mp_obj_t self_in, mp_obj_t value) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_get_brightness(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_adjust_brightness(mp_obj_t self_in, mp_obj_t delta) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_volume(mp_obj_t self_in, mp_obj_t value) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_get_volume(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_adjust_volume(mp_obj_t self_in, mp_obj_t delta) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_light(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_is_pressed(mp_obj_t self_in, mp_obj_t button) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_play_sample(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
|
||||
/***** Extern of Class Definition *****/
|
||||
extern const mp_obj_type_t GalacticUnicorn_type;
|
||||
|
||||
/***** Extern of Class Methods *****/
|
||||
extern void GalacticUnicorn_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
|
||||
extern mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
|
||||
extern mp_obj_t GalacticUnicorn___del__(mp_obj_t self_in);
|
||||
extern mp_obj_t GalacticUnicorn_clear(mp_obj_t self_in);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
//extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_brightness(mp_obj_t self_in, mp_obj_t value);
|
||||
extern mp_obj_t GalacticUnicorn_get_brightness(mp_obj_t self_in);
|
||||
extern mp_obj_t GalacticUnicorn_adjust_brightness(mp_obj_t self_in, mp_obj_t delta);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_volume(mp_obj_t self_in, mp_obj_t value);
|
||||
extern mp_obj_t GalacticUnicorn_get_volume(mp_obj_t self_in);
|
||||
extern mp_obj_t GalacticUnicorn_adjust_volume(mp_obj_t self_in, mp_obj_t delta);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
//extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GalacticUnicorn_light(mp_obj_t self_in);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_is_pressed(mp_obj_t self_in, mp_obj_t button);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_play_sample(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
|
@ -0,0 +1,22 @@
|
|||
set(MOD_NAME galactic_unicorn)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/galactic_unicorn.cpp
|
||||
)
|
||||
pico_generate_pio_header(usermod_${MOD_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/galactic_unicorn.pio)
|
||||
pico_generate_pio_header(usermod_${MOD_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/audio_i2s.pio)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
MODULE_GALATIC_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
|
@ -44,6 +44,8 @@ include(pcf85063a/micropython)
|
|||
|
||||
include(picographics/micropython)
|
||||
include(jpegdec/micropython)
|
||||
include(galactic_unicorn/micropython)
|
||||
|
||||
|
||||
include(modules_py/modules_py)
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ include(adcfft/micropython)
|
|||
# LEDs & Matrices
|
||||
include(plasma/micropython)
|
||||
include(hub75/micropython)
|
||||
include(galactic_unicorn/micropython)
|
||||
|
||||
# Packs
|
||||
include(pico_unicorn/micropython)
|
||||
|
|
Ładowanie…
Reference in New Issue