display fixes and improved neopixels dimming

master
Ondřej Hruška 7 years ago
parent 49a5beee5f
commit 3ad1adc596
  1. 2
      CMakeLists.txt
  2. 4
      display.c
  3. 1
      display.h
  4. 10
      leds.c
  5. 38
      leds.h
  6. 2
      lib/wsrgb.c
  7. 13
      main.c

@ -25,7 +25,7 @@ set(SOURCE_FILES
lib/wsrgb.h
pinout.h
display.c
display.h)
display.h leds.c leds.h)
include_directories(lib
/usr/avr/include/)

@ -13,8 +13,12 @@ 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
};
volatile uint8_t disp_brightness;
void display_show(uint8_t dig0, uint8_t dig1)
{
spi_send(0);
spi_send(0);
spi_send(dig1);
spi_send(dig0);
pin_down(PIN_DISP_STR);

@ -28,6 +28,7 @@
#define DIGIT_9 (SEG_A|SEG_B|SEG_C|SEG_D|SEG_F|SEG_G)
extern const uint8_t disp_digits[10];
extern volatile uint8_t disp_brightness; // place to globally store display brightness
void display_show(uint8_t dig0, uint8_t dig1);
void display_show_number(uint8_t num);

@ -0,0 +1,10 @@
//
// Created by MightyPork on 2017/06/08.
//
#include "lib/color.h"
#include "leds.h"
void leds_set(uint32_t L1, uint32_t L2, uint32_t L3, uint32_t L4);
void leds_show(void);

@ -0,0 +1,38 @@
//
// Created by MightyPork on 2017/06/08.
//
#include <stdint.h>
#include "lib/color.h"
#include "lib/wsrgb.h"
#include "display.h"
#include <math.h>
#ifndef FIRMWARE_LEDS_H
#define FIRMWARE_LEDS_H
uint32_t leds[4];
void leds_set(uint32_t L1, uint32_t L2, uint32_t L3, uint32_t L4)
{
leds[0] = L1;
leds[1] = L2;
leds[2] = L3;
leds[3] = L4;
}
void leds_show(void)
{
xrgb_t arr[4];
for (uint8_t i = 0; i < 4; i++) {
float db = (float)disp_brightness / 255.0f;
arr[i].r = (uint8_t) ((float)rgb24_r(leds[i]) * db);
arr[i].g = (uint8_t) ((float)rgb24_g(leds[i]) * db);
arr[i].b = (uint8_t) ((float)rgb24_b(leds[i]) * db);
}
ws_send_xrgb_array(arr, 4);
//ws_send_rgb24_array(leds, 4);
}
#endif //FIRMWARE_LEDS_H

@ -72,12 +72,14 @@ void ws_send_rgb24(rgb24_t rgb)
/** Send array of colors */
void ws_send_xrgb_array(const xrgb_t rgbs[], const uint8_t length)
{
cli();
for (uint8_t i = 0; i < length; i++) {
const xrgb_t c = rgbs[i];
ws_send_byte(c.g);
ws_send_byte(c.r);
ws_send_byte(c.b);
}
sei();
}
/** Send array of colors */

@ -16,6 +16,7 @@
#include "pinout.h"
#include "display.h"
#include "leds.h"
/**
* Configure pins
@ -24,6 +25,7 @@ void setup_io(void)
{
as_output(PIN_DISP_CP);
as_output(PIN_DISP_D);
pin_up(PIN_DISP_STR);
as_output(PIN_DISP_STR);
as_output(PIN_DISP_OE);
@ -43,7 +45,7 @@ void setup_io(void)
}
// --- LED display brightness control ---
volatile uint8_t disp_brightness;
// disp brightness defined in display.h
#define LIGHT_ADC_CHANNEL 6
/**
@ -141,6 +143,8 @@ ISR(TIMER1_COMPA_vect)
// shut down
pin_down(PIN_PWR_HOLD);
}
leds_show();
}
@ -163,7 +167,7 @@ void main()
// 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);
spi_init_master(SPI_LSB_FIRST, CPOL_1, CPHA_0, SPI_DIV_4);
adc_init(ADC_PRESC_128);
setup_pwm();
@ -177,7 +181,7 @@ void main()
// globally enable interrupts
sei();
uint32_t pixels[4] = {0xFF0000, 0xFFFF00, 0x00FF00, 0x0000FF};
leds_set(0xFFFF00, 0x00FF00, 0x0000FF, 0xFF0000);
uint8_t cnt = 0;
@ -187,8 +191,7 @@ void main()
cnt++;
cnt = cnt % 100;
ws_send_rgb24_array(pixels, 4);
_delay_ms(300);
_delay_ms(150);
sprintf(buf, "BRT = %d\r\n", disp_brightness);
usart_puts(buf);

Loading…
Cancel
Save