Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added enable_dim_neopixel(), disable_dim_neopixel(), set_dim_level() #246

Merged
merged 6 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CFLAGS += -Os -ggdb -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER -DMICROPY_DEBUG_MODULES
else
# -finline-limit can shrink the image size. -finline-limit=80 or so is similar to not having it on.
# There is no simple default value, though.
CFLAGS += -Os -DNDEBUG -flto -finline-limit=57
CFLAGS += -Os -DNDEBUG -flto -finline-limit=49
endif

ifneq ($(FROZEN_DIR),)
Expand Down
18 changes: 18 additions & 0 deletions atmel-samd/bindings/samd/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "autoreload.h"
#include "rgb_led_status.h"

//| :mod:`samd` --- SAMD implementation settings
//| =================================================
Expand Down Expand Up @@ -56,10 +57,27 @@ STATIC mp_obj_t samd_disable_autoreload(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(samd_disable_autoreload_obj, samd_disable_autoreload);

//| .. method:: set_rgb_status_brightness()
//|
//| Set brightness of status neopixel from 0-255
//| `set_rgb_status_brightness` is called.
//|
STATIC mp_obj_t samd_set_rgb_status_brightness(mp_obj_t lvl){
// This must be int. If cast to uint8_t first, will never raise a ValueError.
int brightness_int = mp_obj_get_int(lvl);
if(brightness_int < 0 || brightness_int > 255){
mp_raise_ValueError("Brightness must be between 0 and 255");
}
set_rgb_status_brightness((uint8_t)brightness_int);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(samd_set_rgb_status_brightness_obj, samd_set_rgb_status_brightness);

STATIC const mp_rom_map_elem_t samd_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&samd_enable_autoreload_obj)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&samd_disable_autoreload_obj)},
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&samd_set_rgb_status_brightness_obj)},
};

STATIC MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table);
Expand Down
28 changes: 19 additions & 9 deletions atmel-samd/rgb_led_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "rgb_led_status.h"
#include "samd21_pins.h"

uint8_t rgb_status_brightness = 255;
#ifdef MICROPY_HW_NEOPIXEL
static uint8_t status_neopixel_color[3];
static digitalio_digitalinout_obj_t status_neopixel;
Expand Down Expand Up @@ -94,25 +95,26 @@ void new_status_color(uint32_t rgb) {
if (current_status_color == rgb) {
return;
}
current_status_color = rgb;
uint32_t rgb_adjusted = color_brightness(rgb, rgb_status_brightness);
current_status_color = rgb_adjusted;
#endif

#ifdef MICROPY_HW_NEOPIXEL
if (neopixel_in_use) {
return;
}
status_neopixel_color[0] = (rgb >> 8) & 0xff;
status_neopixel_color[1] = (rgb >> 16) & 0xff;
status_neopixel_color[2] = rgb & 0xff;
status_neopixel_color[0] = (rgb_adjusted >> 8) & 0xff;
status_neopixel_color[1] = (rgb_adjusted >> 16) & 0xff;
status_neopixel_color[2] = rgb_adjusted & 0xff;
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
if (apa102_mosi_in_use || apa102_sck_in_use) {
return;
}
status_apa102_color[5] = rgb & 0xff;
status_apa102_color[6] = (rgb >> 8) & 0xff;
status_apa102_color[7] = (rgb >> 16) & 0xff;
status_apa102_color[5] = rgb_adjusted & 0xff;
status_apa102_color[6] = (rgb_adjusted >> 8) & 0xff;
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;

#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
Expand All @@ -123,18 +125,22 @@ void new_status_color(uint32_t rgb) {
}

void temp_status_color(uint32_t rgb) {
#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK))
uint32_t rgb_adjusted = rgb;
rgb_adjusted = color_brightness(rgb, rgb_status_brightness);
#endif
#ifdef MICROPY_HW_NEOPIXEL
if (neopixel_in_use) {
return;
}
uint8_t colors[3] = {(rgb >> 8) & 0xff, (rgb >> 16) & 0xff, rgb & 0xff};
uint8_t colors[3] = {(rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, rgb_adjusted & 0xff};
common_hal_neopixel_write(&status_neopixel, colors, 3);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
if (apa102_mosi_in_use || apa102_sck_in_use) {
return;
}
uint8_t colors[12] = {0, 0, 0, 0, 0xff, rgb & 0xff, (rgb >> 8) & 0xff, (rgb >> 16) & 0xff, 0x0, 0x0, 0x0, 0x0};
uint8_t colors[12] = {0, 0, 0, 0, 0xff, rgb_adjusted & 0xff, (rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, 0x0, 0x0, 0x0, 0x0};
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_write(&status_apa102, colors, 12);
#else
Expand Down Expand Up @@ -166,3 +172,7 @@ uint32_t color_brightness(uint32_t color, uint8_t brightness) {
return color;
#endif
}

void set_rgb_status_brightness(uint8_t level){
rgb_status_brightness = level;
}
1 change: 1 addition & 0 deletions atmel-samd/rgb_led_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ void temp_status_color(uint32_t rgb);
void clear_temp_status(void);

uint32_t color_brightness(uint32_t color, uint8_t brightness);
void set_rgb_status_brightness(uint8_t level);

#endif // MICROPY_INCLUDED_ATMEL_SAMD_RGB_LED_STATUS_H