From 2d58ca3e1f25c499aeb297a2fef1c0be7d3a55a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 8 Jun 2017 12:55:01 +0200 Subject: [PATCH] neopixel pmos control, power hold implemented --- lib/iopins.h | 4 ++-- main.c | 15 +++++++++++++-- pinout.h | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/iopins.h b/lib/iopins.h index 483319c..f918922 100644 --- a/lib/iopins.h +++ b/lib/iopins.h @@ -108,12 +108,12 @@ bool pin_read_n(uint8_t pin); /** CHeck if pin is low */ -#define pin_is_low(pin) (get_pin(pin) == 0) +#define pin_is_low(pin) (pin_read(pin) == 0) bool pin_is_low_n(uint8_t pin); /** CHeck if pin is high */ -#define pin_is_high(pin) (get_pin(pin) != 0) +#define pin_is_high(pin) (pin_read(pin) != 0) bool pin_is_high_n(uint8_t pin); diff --git a/main.c b/main.c index 03203ff..56eff88 100644 --- a/main.c +++ b/main.c @@ -33,6 +33,8 @@ void setup_io(void) as_input(PIN_PWR_KEY); as_output(PIN_PWR_HOLD); + as_output(PIN_NEOPIXEL_PWRN); + pin_up(PIN_NEOPIXEL_PWRN); // turn neopixels OFF // PIN_LIGHT_SENSE is ADC exclusive, needs no config } @@ -74,13 +76,22 @@ void main() usart_init(BAUD_115200); //usart_isr_rx_enable(true); // enable RX interrupt handler - adc_init(ADC_PRESC_128); setup_io(); - setup_pwm(); + + // Stay on + pin_up(D13); // the on-board LED (also SPI clk) + pin_up(PIN_PWR_HOLD); + // Wait for user to release the power key + while (pin_is_high(PIN_PWR_KEY)); // SPI conf // TODO verify the cpha and cpol. those seem to work, but it's a guess spi_init_master(SPI_LSB_FIRST, CPOL_1, CPHA_0, SPI_DIV_2); + adc_init(ADC_PRESC_128); + setup_pwm(); + + // Turn neopixels ON + pin_down(PIN_NEOPIXEL_PWRN); // globally enable interrupts sei(); diff --git a/pinout.h b/pinout.h index 9f56f64..570b393 100644 --- a/pinout.h +++ b/pinout.h @@ -12,7 +12,7 @@ #define PIN_DISP_D D11 // MOSI #define PIN_DISP_CP D13 // SCK #define PIN_DISP_STR D10 // NSS, unused for SPI -#define PIN_DISP_OE D3 // SCK +#define PIN_DISP_OE D3 // OE (PWM) // Touch keys #define PIN_KEY_1 A0 @@ -25,6 +25,7 @@ // NeoPixel data #define PIN_NEOPIXEL D2 +#define PIN_NEOPIXEL_PWRN D4 // PMOS gate // Power #define PIN_PWR_KEY A4 // Direct input from the power key, used for power-off