circuitpython/atmel-samd/neopixel_status.c
Scott Shawcroft ccbb5e84f9 This introduces an alternative hardware API called nativeio structured around different functions that are typically accelerated by native hardware. Its not meant to reflect the structure of the hardware.
Docs are here: http://tannewt-micropython.readthedocs.io/en/microcontroller/

It differs from upstream's machine in the following ways:

* Python API is identical across ports due to code structure. (Lives in shared-bindings)
* Focuses on abstracting common functionality (AnalogIn) and not representing structure (ADC).
* Documentation lives with code making it easy to ensure they match.
* Pin is split into references (board.D13 and microcontroller.pin.PA17) and functionality (DigitalInOut).
* All nativeio classes claim underlying hardware resources when inited on construction, support Context Managers (aka with statements) and have deinit methods which release the claimed hardware.
* All constructors take pin references rather than peripheral ids. Its up to the implementation to find hardware or throw and exception.
2016-11-21 14:11:52 -08:00

44 lines
1.3 KiB
C

#include "asf/common2/services/delay/delay.h"
#include "asf/sam0/drivers/port/port.h"
#include "mphalport.h"
#include "shared-bindings/nativeio/DigitalInOut.h"
#include "shared-bindings/neopixel_write/__init__.h"
#include "neopixel_status.h"
#include "samd21_pins.h"
#ifdef MICROPY_HW_NEOPIXEL
static uint8_t status_neopixel_color[3];
static nativeio_digitalinout_obj_t status_neopixel;
#endif
void neopixel_status_init() {
#ifdef MICROPY_HW_NEOPIXEL
common_hal_nativeio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
common_hal_nativeio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
#endif
}
void new_status_color(uint8_t r, uint8_t g, uint8_t b) {
#ifdef MICROPY_HW_NEOPIXEL
status_neopixel_color[0] = g;
status_neopixel_color[1] = r;
status_neopixel_color[2] = b;
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3, true);
#endif
}
void temp_status_color(uint8_t r, uint8_t g, uint8_t b) {
#ifdef MICROPY_HW_NEOPIXEL
uint8_t colors[3] = {g, r, b};
common_hal_neopixel_write(&status_neopixel, colors, 3, true);
#endif
}
void clear_temp_status() {
#ifdef MICROPY_HW_NEOPIXEL
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3, true);
#endif
}