Browse Source

borg_hw_led_tester.c etc.: adjustable power consumption

feature/2015
Christian Kroll 10 years ago
parent
commit
e526b4dd4d
  1. 18
      config.in
  2. 47
      src/borg_hw/borg_hw_led_tester.c
  3. 2
      src/borg_hw/config_borg_led_tester.in
  4. 39
      src/uart/uart_commands.c

18
config.in

@ -7,23 +7,27 @@ comment "General Setup"
choice 'Target MCU' \
"ATmega8 atmega8 \
ATmega16 atmega16 \
ATmega164 atmega164 \
ATmega164P atmega164p \
ATmega48 atmega48 \
ATmega48P atmega48p \
ATmega88 atmega88 \
ATmega88P atmega88p \
ATmega168 atmega168 \
ATmega168P atmega168p \
ATmega328 atmega328 \
ATmega328P atmega328p \
ATmega16 atmega16 \
ATmega32 atmega32 \
ATmega164 atmega164 \
ATmega164P atmega164p \
ATmega324 atmega324 \
ATmega324P atmega324p \
ATmega32U4 atmega32u4 \
ATmega328 atmega328 \
ATmega328P atmega328p \
ATmega644 atmega644 \
ATmega644P atmega644p \
ATmega1280 atmega1280 \
ATmega1284 atmega1284 \
ATmega1284P atmega1284p \
ATmega1280 atmega1280 \
ATmega2560 atmega2560 \
ATmega32U4 atmega32u4 \
ATmega8515 atmega8515" \
'ATmega32' MCU

47
src/borg_hw/borg_hw_led_tester.c

@ -1,6 +1,7 @@
#include "../config.h"
#include "../makros.h"
#include <stdbool.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/wdt.h>
@ -21,23 +22,27 @@
# define TIMER0_COMPARE(t) OCR0A = t
# define TIMER0_INT_ENABLE() TIMSK0 = _BV(OCIE0A)
# define TIMER0_ISR TIMER0_COMPA_vect
#else // ATmega8
#elif defined(__AVR_ATmega8__) || \
defined(__AVR_ATmega8A__) // ATmega8
# define TIMER0_OFF() TCCR0 = 0
# define TIMER0_MODE_CS256() TCCR0 = _BV(CS02)
# define TIMER0_RESET() TCNT0 = 0
# define TIMER0_COMPARE(t) TCNT0 = (0xff - t)
# define TIMER0_INT_ENABLE() TIMSK = _BV(TOIE0)
# define TIMER0_ISR TIMER0_OVF_vect
#else
# error MCU not supported by LED Tester.
#endif
bool g_highpower = false;
/* Output data of the current row to the column drivers:
* Column: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
* Pin: PD2 PD3 PC5 PC4 PC3 PC2 PC1 PC0 PD7 PD6 PB5 PB4 PB3 PB2 PB1 PB0
*/
#define DISPLAY_PINS_B (_BV(PB5)|_BV(PB4)|_BV(PB3)|_BV(PB2)|_BV(PB1)|_BV(PB0))
#define DISPLAY_PINS_C (_BV(PC5)|_BV(PC4)|_BV(PC3)|_BV(PC2)|_BV(PC1)|_BV(PC0))
#define DISPLAY_PINS_D (_BV(PD7)|_BV(PD6)|_BV(PD3)|_BV(PD2))
#define DISPLAY_B (_BV(PB5)|_BV(PB4)|_BV(PB3)|_BV(PB2)|_BV(PB1)|_BV(PB0))
#define DISPLAY_C (_BV(PC5)|_BV(PC4)|_BV(PC3)|_BV(PC2)|_BV(PC1)|_BV(PC0))
#define DISPLAY_D (_BV(PD7)|_BV(PD6)|_BV(PD3)|_BV(PD2))
#define ROW_DUMMY_PORT PORTB
#define ROW_DUMMY_DDR DDRB
@ -53,9 +58,9 @@ unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES];
// switch to next row
static void nextrow(uint8_t row) {
// switch off all columns for now
PORTB &= ~(DISPLAY_PINS_B);
PORTC &= ~(DISPLAY_PINS_C);
PORTD &= ~(DISPLAY_PINS_D);
PORTB &= ~(DISPLAY_B);
PORTC &= ~(DISPLAY_C);
PORTD &= ~(DISPLAY_D);
// short delay loop, to ensure proper deactivation of the drivers
unsigned char i;
@ -70,7 +75,9 @@ static void nextrow(uint8_t row) {
} else { /* fake rows simulated by resistors */
// remaining rows: unblock resistor MOSFET, block LED MOSFET
ROW_LED_PORT &= ~_BV(ROW_LED_PIN); // block LED MOSFET
ROW_DUMMY_PORT |= _BV(ROW_DUMMY_PIN); // block resistor MOSFET
if (g_highpower) {
ROW_DUMMY_PORT |= _BV(ROW_DUMMY_PIN); // unblock resistor MOSFET
}
}
// another delay loop, to ensure that the drivers are ready
@ -92,9 +99,9 @@ static void rowshow(unsigned char row, unsigned char plane) {
TIMER0_COMPARE(ocr_table[plane]);
uint8_t port_b = (PORTB & ~DISPLAY_PINS_B) | (0x3f & pixmap[plane][row][0]);
uint8_t port_c = (PORTC & ~DISPLAY_PINS_C) | (0x3f & pixmap[plane][row][1]);
uint8_t port_d = (PORTD & ~DISPLAY_PINS_D) | (0xc0 & pixmap[plane][row][0]);
uint8_t port_b = (PORTB & ~DISPLAY_B) | (DISPLAY_B & pixmap[plane][row][0]);
uint8_t port_c = (PORTC & ~DISPLAY_C) | (DISPLAY_C & pixmap[plane][row][1]);
uint8_t port_d = (PORTD & ~DISPLAY_D) | (0xc0 & pixmap[plane][row][0]);
if (0x40u & pixmap[plane][row][1]) port_d |= _BV(PD3);
if (0x80u & pixmap[plane][row][1]) port_d |= _BV(PD2);
@ -130,9 +137,9 @@ ISR(TIMER0_ISR) {
void timer0_off() {
cli();
// switch off all columns
PORTB &= ~(DISPLAY_PINS_B);
PORTC &= ~(DISPLAY_PINS_C);
PORTD &= ~(DISPLAY_PINS_D);
PORTB &= ~(DISPLAY_B);
PORTC &= ~(DISPLAY_C);
PORTD &= ~(DISPLAY_D);
TIMER0_OFF();
sei();
}
@ -149,16 +156,16 @@ static void timer0_on() {
void borg_hw_init() {
// switch column and row ports to output mode
DDRB |= DISPLAY_PINS_B;
DDRC |= DISPLAY_PINS_C;
DDRD |= DISPLAY_PINS_D;
DDRB |= DISPLAY_B;
DDRC |= DISPLAY_C;
DDRD |= DISPLAY_D;
ROW_DUMMY_DDR |= _BV(ROW_DUMMY_PIN);
ROW_LED_DDR |= _BV(ROW_LED_PIN);
// switch off all columns for now
PORTB &= ~(DISPLAY_PINS_B);
PORTC &= ~(DISPLAY_PINS_C);
PORTD &= ~(DISPLAY_PINS_D);
PORTB &= ~(DISPLAY_B);
PORTC &= ~(DISPLAY_C);
PORTD &= ~(DISPLAY_D);
// switch off all rows
ROW_DUMMY_PORT &= ~_BV(ROW_DUMMY_PIN);

2
src/borg_hw/config_borg_led_tester.in

@ -1,6 +1,8 @@
mainmenu_option next_comment
comment "LED Tester Setup"
define_int LED_TESTER 1
bool "Higher Contrast" HIGH_CONTRAST n
bool "UART Support" UART_SUPPORT n

39
src/uart/uart_commands.c

@ -19,6 +19,10 @@
#include "uart.h"
#include "uart_commands.h"
#ifdef LED_TESTER
extern bool g_highpower;
#endif
#ifndef USE_UART1
# define UART_PUTS(STR) uart_puts(STR)
# define UART_PUTS_P(STR) uart_puts_p(STR)
@ -34,7 +38,7 @@
#ifdef SCROLLTEXT_BUFFER_SIZE
# define UART_BUFFER_SIZE (SCROLLTEXT_BUFFER_SIZE + 8)
#else
# define UART_BUFFER_SIZE 136
# define UART_BUFFER_SIZE 32
#endif
char g_rx_buffer[UART_BUFFER_SIZE];
@ -48,7 +52,7 @@ extern volatile unsigned char reverseMode;
#if (!(defined(eeprom_update_block) && \
((E2PAGESIZE == 2) || (E2PAGESIZE == 4) || (E2PAGESIZE == 8)))) || \
!(defined(ANIMATION_TESTS))
!defined(ANIMATION_TESTS) || !(defined(SCROLLTEXT_SUPPORT))
char const UART_STR_NOTIMPL[] PROGMEM = "Not implemented."CR;
#endif
@ -62,9 +66,14 @@ char const UART_STR_GAMETX_ERR[] PROGMEM = "No text messages during games."CR;
char const UART_STR_UART_ERR[] PROGMEM = "Transmission error."CR;
char const UART_STR_UNKNOWN[] PROGMEM = "Unknown command or syntax error."CR;
char const UART_STR_TOOLONG[] PROGMEM = CR"Command is too long."CR;
#ifdef LED_TESTER
char const UART_STR_HELP[] PROGMEM = "Allowed commands: erase help mode "
"msg next power_lo power_hi prev "
"reset scroll test"CR;
#else
char const UART_STR_HELP[] PROGMEM = "Allowed commands: erase help mode "
"msg next prev reset scroll test"CR;
#endif
char const UART_CMD_ERASE[] PROGMEM = "erase";
char const UART_CMD_HELP[] PROGMEM = "help";
char const UART_CMD_MODE[] PROGMEM = "mode";
@ -74,6 +83,10 @@ char const UART_CMD_PREV[] PROGMEM = "prev";
char const UART_CMD_RESET[] PROGMEM = "reset";
char const UART_CMD_SCROLL[] PROGMEM = "scroll ";
char const UART_CMD_TEST[] PROGMEM = "test";
#ifdef LED_TESTER
char const UART_CMD_PWRLO[] PROGMEM = "power_lo";
char const UART_CMD_PWRHI[] PROGMEM = "power_hi";
#endif
#ifdef ANIMATION_TESTS
char const UART_STR_TEST_EXIT[] PROGMEM = "Press ENTER to exit test."CR;
@ -178,6 +191,8 @@ static void uartcmd_simple_message(void) {
#endif
uartcmd_permit();
}
#else
UART_PUTS_P(UART_STR_NOTIMPL);
#endif
}
@ -186,24 +201,26 @@ static void uartcmd_simple_message(void) {
* Displays a message which may use the complete range of scrolltext commands.
*/
static void uartcmd_scroll_message(void) {
#ifdef SCROLLTEXT_SUPPORT
# ifdef SCROLLTEXT_SUPPORT
if (uartcmd_processing_allowed()) {
uartcmd_forbid();
#ifdef JOYSTICK_SUPPORT
# ifdef JOYSTICK_SUPPORT
if (waitForFire) {
waitForFire = 0;
#endif
# endif
// text must not be longer than the scroll text buffer
g_rx_buffer[7 + SCROLLTEXT_BUFFER_SIZE - 1] = 0;
scrolltext(&g_rx_buffer[7]);
#ifdef JOYSTICK_SUPPORT
# ifdef JOYSTICK_SUPPORT
waitForFire = 1;
} else {
UART_PUTS_P(UART_STR_GAMETX_ERR);
}
#endif
# endif
uartcmd_permit();
}
#else
UART_PUTS_P(UART_STR_NOTIMPL);
#endif
}
@ -504,6 +521,12 @@ void uartcmd_process(void) {
} else if ((!strncmp_P(g_rx_buffer, UART_CMD_TEST, 4)) &&
(g_rx_buffer[4] <= ' ')) {
uartcmd_test();
#ifdef LED_TESTER
} else if (!strncmp_P(g_rx_buffer, UART_CMD_PWRLO, UART_BUFFER_SIZE)) {
g_highpower = false;
} else if (!strncmp_P(g_rx_buffer, UART_CMD_PWRHI, UART_BUFFER_SIZE)) {
g_highpower = true;
#endif
} else if (g_rx_buffer[0] != 0) {
UART_PUTS_P(UART_STR_UNKNOWN);
}

Loading…
Cancel
Save