From 49a5beee5f69c973550df59d84a2afb3dc6bf43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 8 Jun 2017 15:45:30 +0200 Subject: [PATCH] display interfacing logic, neopixels working --- CMakeLists.txt | 5 +++-- Makefile | 1 + display.c | 31 +++++++++++++++++++++++++++++++ display.h | 35 +++++++++++++++++++++++++++++++++++ lib/wsrgb.c | 3 +++ main.c | 14 +++++++++----- 6 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 display.c create mode 100644 display.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a07feb1..b7411e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ set(CMAKE_CXX_STANDARD GNU99) set(SOURCE_FILES main.c - debo_config.h lib/calc.h lib/iopins.c lib/iopins.h @@ -24,7 +23,9 @@ set(SOURCE_FILES lib/color.h lib/wsrgb.c lib/wsrgb.h - pinout.h) + pinout.h + display.c + display.h) include_directories(lib /usr/avr/include/) diff --git a/Makefile b/Makefile index 1f54b4a..89ac099 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ OBJS += lib/adc.o OBJS += lib/debounce.o OBJS += lib/wsrgb.o OBJS += lib/color.o +OBJS += display.o # Dirs with header files INCL_DIRS = . lib/ diff --git a/display.c b/display.c new file mode 100644 index 0000000..317fe0e --- /dev/null +++ b/display.c @@ -0,0 +1,31 @@ +// +// Created by MightyPork on 2017/06/08. +// + +#include +#include +#include +#include "pinout.h" + +#include "display.h" + +const uint8_t disp_digits[10] = { + DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9 +}; + +void display_show(uint8_t dig0, uint8_t dig1) +{ + spi_send(dig1); + spi_send(dig0); + pin_down(PIN_DISP_STR); + pin_up(PIN_DISP_STR); +} + +void display_show_number(uint8_t num) { + uint8_t tens = num/10; + uint8_t ones = num - tens*10; + uint8_t dig0 = tens ? disp_digits[tens] : 0; + uint8_t dig1 = disp_digits[ones]; + dig1 |= SEG_H; + display_show(dig0, dig1); +} diff --git a/display.h b/display.h new file mode 100644 index 0000000..81c7960 --- /dev/null +++ b/display.h @@ -0,0 +1,35 @@ +// +// Created by MightyPork on 2017/06/08. +// + +#ifndef FIRMWARE_DISPLAY_H +#define FIRMWARE_DISPLAY_H + +#include + +#define SEG_A _BV(0) +#define SEG_B _BV(1) +#define SEG_C _BV(2) +#define SEG_D _BV(3) +#define SEG_E _BV(4) +#define SEG_F _BV(5) +#define SEG_G _BV(6) +#define SEG_H _BV(7) + +#define DIGIT_0 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F) +#define DIGIT_1 (SEG_B|SEG_C) +#define DIGIT_2 (SEG_A|SEG_B|SEG_D|SEG_E|SEG_G) +#define DIGIT_3 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_G) +#define DIGIT_4 (SEG_B|SEG_C|SEG_F|SEG_G) +#define DIGIT_5 (SEG_A|SEG_C|SEG_D|SEG_F|SEG_G) +#define DIGIT_6 (SEG_A|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G) +#define DIGIT_7 (SEG_A|SEG_B|SEG_C|SEG_F) +#define DIGIT_8 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G) +#define DIGIT_9 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_F|SEG_G) + +extern const uint8_t disp_digits[10]; + +void display_show(uint8_t dig0, uint8_t dig1); +void display_show_number(uint8_t num); + +#endif //FIRMWARE_DISPLAY_H diff --git a/lib/wsrgb.c b/lib/wsrgb.c index a84e22a..bd66e69 100644 --- a/lib/wsrgb.c +++ b/lib/wsrgb.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "iopins.h" #include "nsdelay.h" @@ -82,12 +83,14 @@ void ws_send_xrgb_array(const xrgb_t rgbs[], const uint8_t length) /** Send array of colors */ void ws_send_rgb24_array(const rgb24_t rgbs[], const uint8_t length) { + cli(); for (uint8_t i = 0; i < length; i++) { const rgb24_t c = rgbs[i]; ws_send_byte(rgb24_g(c)); ws_send_byte(rgb24_r(c)); ws_send_byte(rgb24_b(c)); } + sei(); } //#define ws_send_rgb24_array(rgbs, length) __ws_send_array_proto((rgbs), (length), rgb24) diff --git a/main.c b/main.c index 027ca02..9a93168 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include // C header for int types like uint8_t #include // C header for the bool type #include +#include // Include stuff from the library #include "lib/iopins.h" @@ -14,6 +15,7 @@ #include "lib/debounce.h" #include "pinout.h" +#include "display.h" /** * Configure pins @@ -170,21 +172,23 @@ void main() // Turn neopixels power ON - voltage will have stabilized by now // and no glitches should occur pin_down(PIN_NEOPIXEL_PWRN); + ws_init(); // globally enable interrupts sei(); + uint32_t pixels[4] = {0xFF0000, 0xFFFF00, 0x00FF00, 0x0000FF}; + uint8_t cnt = 0; char buf[100]; while (1) { - pin_down(PIN_DISP_STR); - spi_send(cnt); - spi_send(cnt); - pin_up(PIN_DISP_STR); + display_show_number(cnt); cnt++; + cnt = cnt % 100; - _delay_ms(100); + ws_send_rgb24_array(pixels, 4); + _delay_ms(300); sprintf(buf, "BRT = %d\r\n", disp_brightness); usart_puts(buf);