display interfacing logic, neopixels working

master
Ondřej Hruška 7 years ago
parent 130e7fd781
commit 49a5beee5f
  1. 5
      CMakeLists.txt
  2. 1
      Makefile
  3. 31
      display.c
  4. 35
      display.h
  5. 3
      lib/wsrgb.c
  6. 14
      main.c

@ -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/)

@ -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/

@ -0,0 +1,31 @@
//
// Created by MightyPork on 2017/06/08.
//
#include <stdint.h>
#include <iopins.h>
#include <spi.h>
#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);
}

@ -0,0 +1,35 @@
//
// Created by MightyPork on 2017/06/08.
//
#ifndef FIRMWARE_DISPLAY_H
#define FIRMWARE_DISPLAY_H
#include <stdint.h>
#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

@ -1,6 +1,7 @@
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include <avr/interrupt.h>
#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)

@ -5,6 +5,7 @@
#include <stdint.h> // C header for int types like uint8_t
#include <stdbool.h> // C header for the bool type
#include <stdio.h>
#include <wsrgb.h>
// 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);

Loading…
Cancel
Save