summaryrefslogtreecommitdiff
path: root/atmel-samd
diff options
context:
space:
mode:
authorAsher Lieber <lieber.asher@gmail.com>2017-09-12 15:09:22 -0400
committerScott Shawcroft <scott@tannewt.org>2017-09-12 12:09:22 -0700
commit5aa8922038a5f0ee07c7c36a3d8eab0547f585bc (patch)
treea9ef4ac17191e62341db4b2ac208d6ce321472ff /atmel-samd
parentdd72fe694526d2b468e189b70ae732f7568fe6e4 (diff)
add set_rgb_status_brightness (#246)
Add set_rgb_status_brightness() via `samd.rgb_status_brightness`. Fixes #162.
Diffstat (limited to 'atmel-samd')
-rw-r--r--atmel-samd/Makefile2
-rw-r--r--atmel-samd/bindings/samd/__init__.c18
-rw-r--r--atmel-samd/rgb_led_status.c28
-rw-r--r--atmel-samd/rgb_led_status.h1
4 files changed, 39 insertions, 10 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index 6fb2f1d67..1e5fe110d 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -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),)
diff --git a/atmel-samd/bindings/samd/__init__.c b/atmel-samd/bindings/samd/__init__.c
index cddb25f36..1634d8daa 100644
--- a/atmel-samd/bindings/samd/__init__.c
+++ b/atmel-samd/bindings/samd/__init__.c
@@ -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
//| =================================================
@@ -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);
diff --git a/atmel-samd/rgb_led_status.c b/atmel-samd/rgb_led_status.c
index f3c20992c..83d3f9916 100644
--- a/atmel-samd/rgb_led_status.c
+++ b/atmel-samd/rgb_led_status.c
@@ -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;
@@ -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);
@@ -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
@@ -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;
+}
diff --git a/atmel-samd/rgb_led_status.h b/atmel-samd/rgb_led_status.h
index 67dd20242..35bebda85 100644
--- a/atmel-samd/rgb_led_status.h
+++ b/atmel-samd/rgb_led_status.h
@@ -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