Browse Source

just works, before ws2812

master
Marc Poulhiès 7 years ago
parent
commit
40dc32eb6a
  1. 5
      Makefile
  2. 215
      lcd1602d.c
  3. 48
      lcd1602d.h
  4. 321
      main.c
  5. 53
      uberframe.c
  6. 2
      uberframe.h

5
Makefile

@ -20,6 +20,11 @@ CFLAGS += -DSPI_PORT=$(SPI_PORT)
CFLAGS += -DCE_PIN=$(CE_PIN)
CFLAGS += -DCS_PIN=$(CS_PIN)
CFLAGS += -DIRQ_PIN=$(IRQ_PIN)
CFLAGS += -DENABLE_NRF_COMM=1
CFLAGS += -DENABLE_WS2812=1
##CFLAGS += -I$(HOME)/git/ubberFrame
include $(RIOTBASE)/Makefile.include

215
lcd1602d.c

@ -0,0 +1,215 @@
#include "lcd1602d.h"
#include "periph/gpio.h"
#include "xtimer.h"
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
#define LOW 0
#define HIGH 1
void lcd1602d_init_lcd(struct lcd_ctx *lcd){
gpio_init(lcd->rs_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(lcd->enable_pin, GPIO_DIR_OUT, GPIO_NOPULL);
lcd->currline = 0;
xtimer_usleep(50000);
gpio_clear(lcd->rs_pin);
gpio_clear(lcd->enable_pin);
lcd1602d_write4bits(lcd, 0x03);
xtimer_usleep(4500);
lcd1602d_write4bits(lcd, 0x03);
xtimer_usleep(4500);
lcd1602d_write4bits(lcd, 0x03);
xtimer_usleep(150);
lcd1602d_write4bits(lcd, 0x02);
lcd1602d_command(lcd, LCD_FUNCTIONSET | lcd->displayfunctions);
lcd->displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
lcd1602d_display(lcd);
// clear it off
lcd1602d_clear(lcd);
// Initialize to default text direction (for romance languages)
lcd->displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
lcd1602d_command(lcd, LCD_ENTRYMODESET | lcd->displaymode);
}
void lcd1602d_clear(struct lcd_ctx* lcd)
{
lcd1602d_command(lcd, LCD_CLEARDISPLAY); // clear display, set cursor position to zero
xtimer_usleep(2000); // this command takes a long time!
}
void lcd1602d_home(struct lcd_ctx* lcd)
{
lcd1602d_command(lcd, LCD_RETURNHOME); // set cursor position to zero
xtimer_usleep(2000); // this command takes a long time!
}
void lcd1602d_setCursor(struct lcd_ctx* lcd, uint8_t col, uint8_t row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row >= lcd->numlines ) {
row = lcd->numlines-1; // we count rows starting w/0
}
lcd1602d_command(lcd, LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
// Turn the display on/off (quickly)
void lcd1602d_noDisplay(struct lcd_ctx* lcd) {
lcd->displaycontrol &= ~LCD_DISPLAYON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
void lcd1602d_display(struct lcd_ctx* lcd) {
lcd->displaycontrol |= LCD_DISPLAYON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
// Turns the underline cursor on/off
void lcd1602d_noCursor(struct lcd_ctx* lcd) {
lcd->displaycontrol &= ~LCD_CURSORON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
void lcd1602d_cursor(struct lcd_ctx* lcd) {
lcd->displaycontrol |= LCD_CURSORON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
// Turn on and off the blinking cursor
void lcd1602d_noBlink(struct lcd_ctx* lcd) {
lcd->displaycontrol &= ~LCD_BLINKON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
void lcd1602d_blink(struct lcd_ctx* lcd) {
lcd->displaycontrol |= LCD_BLINKON;
lcd1602d_command(lcd, LCD_DISPLAYCONTROL | lcd->displaycontrol);
}
// These commands scroll the display without changing the RAM
void lcd1602d_scrollDisplayLeft(struct lcd_ctx* lcd) {
lcd1602d_command(lcd, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void lcd1602d_scrollDisplayRight(struct lcd_ctx* lcd) {
lcd1602d_command(lcd, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void lcd1602d_leftToRight(struct lcd_ctx* lcd) {
lcd->displaymode |= LCD_ENTRYLEFT;
lcd1602d_command(lcd, LCD_ENTRYMODESET | lcd->displaymode);
}
// This is for text that flows Right to Left
void lcd1602d_rightToLeft(struct lcd_ctx* lcd) {
lcd->displaymode &= ~LCD_ENTRYLEFT;
lcd1602d_command(lcd, LCD_ENTRYMODESET | lcd->displaymode);
}
// This will 'right justify' text from the cursor
void lcd1602d_autoscroll(struct lcd_ctx* lcd) {
lcd->displaymode |= LCD_ENTRYSHIFTINCREMENT;
lcd1602d_command(lcd, LCD_ENTRYMODESET | lcd->displaymode);
}
// This will 'left justify' text from the cursor
void lcd1602d_noAutoscroll(struct lcd_ctx* lcd) {
lcd->displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
lcd1602d_command(lcd, LCD_ENTRYMODESET | lcd->displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void lcd1602d_createChar(struct lcd_ctx* lcd, uint8_t location, uint8_t charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
lcd1602d_command(lcd, LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
lcd1602d_write(lcd, charmap[i]);
}
}
void lcd1602d_command(struct lcd_ctx* lcd, uint8_t value) {
lcd1602d_send(lcd, value, LOW);
}
void lcd1602d_write(struct lcd_ctx* lcd, uint8_t value) {
lcd1602d_send(lcd, value, HIGH);
// return 1; // assume sucess
}
void lcd1602d_printstr(struct lcd_ctx* lcd, int col, int row, const char* value){
lcd1602d_setCursor(lcd, col, row);
while(*value){
lcd1602d_write(lcd, *value);
value++;
}
}
void lcd1602d_send(struct lcd_ctx* lcd, uint8_t value, uint8_t mode) {
if (mode)
gpio_set(lcd->rs_pin);
else
gpio_clear(lcd->rs_pin);
lcd1602d_write4bits(lcd, value>>4);
lcd1602d_write4bits(lcd, value);
}
void lcd1602d_write4bits(struct lcd_ctx* lcd, uint8_t value) {
for (int i = 0; i < 4; i++) {
gpio_init(lcd->data_pins[i], GPIO_DIR_OUT, GPIO_NOPULL);
if ((value >> i) & 0x01)
gpio_set(lcd->data_pins[i]);
else
gpio_clear(lcd->data_pins[i]);
}
lcd1602d_pulseEnable(lcd);
}
void lcd1602d_pulseEnable(struct lcd_ctx* lcd) {
gpio_clear(lcd->enable_pin);
xtimer_usleep(1);
gpio_set(lcd->enable_pin);
xtimer_usleep(1); // enable pulse must be >450ns
gpio_clear(lcd->enable_pin);
xtimer_usleep(100); // commands need > 37us to settle
}

48
lcd1602d.h

@ -0,0 +1,48 @@
#pragma once
#include <inttypes.h>
#include "periph/gpio.h"
struct lcd_ctx {
gpio_t rs_pin;
gpio_t enable_pin;
gpio_t data_pins[4];
uint8_t displayfunctions;
uint8_t displaymode;
uint8_t displaycontrol;
uint8_t numlines;
int currline;
};
void lcd1602d_setCursor(struct lcd_ctx* lcd, uint8_t col, uint8_t row);
void lcd1602d_display(struct lcd_ctx* lcd);
void lcd1602d_noDisplay(struct lcd_ctx* lcd);
void lcd1602d_noCursor(struct lcd_ctx* lcd);
void lcd1602d_cursor(struct lcd_ctx* lcd);
void lcd1602d_noBlink(struct lcd_ctx* lcd);
void lcd1602d_blink(struct lcd_ctx* lcd);
void lcd1602d_scrollDisplayLeft(struct lcd_ctx* lcd);
void lcd1602d_scrollDisplayRight(struct lcd_ctx* lcd);
void lcd1602d_leftToRight(struct lcd_ctx* lcd);
void lcd1602d_rightToLeft(struct lcd_ctx* lcd);
void lcd1602d_autoscroll(struct lcd_ctx* lcd);
void lcd1602d_noAutoscroll(struct lcd_ctx* lcd);
void lcd1602d_createChar(struct lcd_ctx* lcd, uint8_t location, uint8_t charmap[]);
void lcd1602d_clear(struct lcd_ctx* lcd);
void lcd1602d_write4bits(struct lcd_ctx* lcd, uint8_t value);
void lcd1602d_init_lcd(struct lcd_ctx *lcd);
void lcd1602d_command(struct lcd_ctx* lcd, uint8_t value) ;
void lcd1602d_send(struct lcd_ctx* lcd, uint8_t value, uint8_t mode);
void lcd1602d_pulseEnable(struct lcd_ctx* lcd);
void lcd1602d_write(struct lcd_ctx* lcd, uint8_t value);
void lcd1602d_printstr(struct lcd_ctx* lcd, int col, int row, const char* value);
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

321
main.c

@ -31,17 +31,20 @@
#error "IRQ_PIN not defined"
#endif
#include "periph/spi.h"
#ifdef ENABLE_NRF_COMM
#include "nrf24l01p_settings.h"
#include "nrf24l01p.h"
#include "nrf24l01p_settings.h"
#endif
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <board.h>
#include <time.h>
#include "nrf24l01p.h"
#include "nrf24l01p_settings.h"
#include "periph/spi.h"
#include <string.h>
#include "periph/gpio.h"
#include "xtimer.h"
#include "shell.h"
@ -49,11 +52,18 @@
#include "thread.h"
#include "msg.h"
#include "cpu.h"
#include <periph/adc.h>
#include "periph_conf.h"
#include "lcd1602d.h"
#include "uberframe.h"
//#include "uberWrap.h"
#define TEST_RX_MSG 1
#ifdef ENABLE_NRF_COMM
static int cmd_uber_setup(int argc, char **argv);
static int cmd_send(int argc, char **argv);
static int cmd_get_status(int argc, char **argv);
@ -65,19 +75,34 @@ static int cmd_set_channel(int argc, char **argv);
static int cmd_set_aa(int argc, char **argv);
static int cmd_get_rf_setup(int argc, char **argv);
static int cmd_set_dpl(int argc, char **argv);
#endif
void printbin(unsigned byte);
void print_register(char reg, int num_bytes);
static gpio_t led = GPIO_PIN(PORT_F, 1);
static unsigned int sender_pid = KERNEL_PID_UNDEF;
static unsigned int display_pid = KERNEL_PID_UNDEF;
#ifdef ENABLE_NRF_COMM
static nrf24l01p_t nrf24l01p_0;
static unsigned int sender_pid = KERNEL_PID_UNDEF;
#endif
struct lcd_ctx lcd = {
.rs_pin = GPIO_PIN(PORT_E, 5),
.enable_pin = GPIO_PIN(PORT_E,4),
.data_pins = {GPIO_PIN(PORT_D,0),GPIO_PIN(PORT_D,1),GPIO_PIN(PORT_D,2),GPIO_PIN(PORT_D,3)},
.displayfunctions = (LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS),
.numlines = 2,
};
/**
* define some additional shell commands
*/
static const shell_command_t shell_commands[] = {
#ifdef ENABLE_NRF_COMM
{"setaa", "set auto ack", cmd_set_aa },
{"setchannel", "set channel", cmd_set_channel },
{"status", "get status value", cmd_get_status },
@ -89,9 +114,124 @@ static const shell_command_t shell_commands[] = {
{ "it", "init transceiver", cmd_its },
{ "send", "send 32 bytes data", cmd_send },
{ "ubersetup", "uber setup", cmd_uber_setup},
#endif
{ NULL, NULL, NULL }
};
// ROTARY
// No complete step yet.
#define DIR_NONE 0x0
// Clockwise step.
#define DIR_CW 0x10
// Anti-clockwise step.
#define DIR_CCW 0x20
#define R_START 0x0
#ifdef HALF_STEP
// Use the half-step state table (emits a code at 00 and 11)
#define R_CCW_BEGIN 0x1
#define R_CW_BEGIN 0x2
#define R_START_M 0x3
#define R_CW_BEGIN_M 0x4
#define R_CCW_BEGIN_M 0x5
const unsigned char ttable[6][4] = {
// R_START (00)
{R_START_M, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CCW_BEGIN
{R_START_M | DIR_CCW, R_START, R_CCW_BEGIN, R_START},
// R_CW_BEGIN
{R_START_M | DIR_CW, R_CW_BEGIN, R_START, R_START},
// R_START_M (11)
{R_START_M, R_CCW_BEGIN_M, R_CW_BEGIN_M, R_START},
// R_CW_BEGIN_M
{R_START_M, R_START_M, R_CW_BEGIN_M, R_START | DIR_CW},
// R_CCW_BEGIN_M
{R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW},
};
#else
// Use the full-step state table (emits a code at 00 only)
#define R_CW_FINAL 0x1
#define R_CW_BEGIN 0x2
#define R_CW_NEXT 0x3
#define R_CCW_BEGIN 0x4
#define R_CCW_FINAL 0x5
#define R_CCW_NEXT 0x6
const unsigned char ttable[7][4] = {
// R_START
{R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CW_FINAL
{R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
// R_CW_BEGIN
{R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
// R_CW_NEXT
{R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
// R_CCW_BEGIN
{R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
// R_CCW_FINAL
{R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
// R_CCW_NEXT
{R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
};
#endif
/* #define R_START 0x0 */
/* #define R_CCW_BEGIN 0x1 */
/* #define R_CW_BEGIN 0x2 */
/* #define R_START_M 0x3 */
/* #define R_CW_BEGIN_M 0x4 */
/* #define R_CCW_BEGIN_M 0x5 */
/* const unsigned char ttable[6][4] = { */
/* // R_START (00) */
/* {R_START_M, R_CW_BEGIN, R_CCW_BEGIN, R_START}, */
/* // R_CCW_BEGIN */
/* {R_START_M | DIR_CCW, R_START, R_CCW_BEGIN, R_START}, */
/* // R_CW_BEGIN */
/* {R_START_M | DIR_CW, R_CW_BEGIN, R_START, R_START}, */
/* // R_START_M (11) */
/* {R_START_M, R_CCW_BEGIN_M, R_CW_BEGIN_M, R_START}, */
/* // R_CW_BEGIN_M */
/* {R_START_M, R_START_M, R_CW_BEGIN_M, R_START | DIR_CW}, */
/* // R_CCW_BEGIN_M */
/* {R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW}, */
/* }; */
unsigned int state = R_START;
/* gpio_t b1 = GPIO_PIN(PORT_C, 7); */
/* gpio_t b2 = GPIO_PIN(PORT_D, 6); */
/* void rotary_cb(void *unused __attribute__((unused))) { */
/* unsigned int b1_v = gpio_read(b1) ? 1 : 0; */
/* unsigned int b2_v = gpio_read(b2) ? 1 : 0; */
/* unsigned char pinstate = ( b1_v? 2 : 0) | (b2_v ? 1 : 0); */
/* /\* history[history_cnt] = pinstate; *\/ */
/* /\* history_cnt++; *\/ */
/* /\* printf("state %d pinstate : %x, b1 %d b2 %d\n", state, pinstate, b1_v, b2_v); *\/ */
/* state = ttable[state & 0xf][pinstate]; */
/* switch(state & 0x30){ */
/* case DIR_CCW: */
/* printf("CCW\n"); */
/* break; */
/* case DIR_CW: */
/* printf("CW\n"); */
/* break; */
/* case DIR_NONE: */
/* // printf("noevent found\n"); */
/* break; */
/* default: */
/* // printf("none of the above ?! %d\n", state); */
/* break; */
/* } */
/* printf("boom\n"); */
/* } */
//END ROTARY
void prtbin(unsigned byte)
{
for (char i = 0; i < 8; i++) {
@ -101,6 +241,8 @@ void prtbin(unsigned byte)
puts("\n");
}
#ifdef ENABLE_NRF_COMM
/**
* @print register
*/
@ -139,7 +281,14 @@ void print_register(char reg, int num_bytes)
}
}
}
#endif
char display_handler_stack[THREAD_STACKSIZE_MAIN];
static char dest_str[256] = {0};
static int dest = 0;
#ifdef ENABLE_NRF_COMM
char tx_handler_stack[THREAD_STACKSIZE_MAIN];
/* RX handler that waits for a message from the ISR */
@ -152,11 +301,39 @@ void *nrf24l01p_tx_thread(void *arg){
while (msg_receive(&m)) {
printf("nrf24l01p_tx got a message\n");
// lcd1602d_printstr(&lcd, 0, 1, dest_str);
lcd1602d_printstr(&lcd, 10, 1, "SEND...");
cmd_send(4, (char**)m.content.ptr);
lcd1602d_printstr(&lcd, 10, 1, "IDLE ");
}
return NULL;
}
#endif
void *display_thread(void *arg){
msg_t msg_q[1];
msg_init_queue(msg_q, 1);
display_pid = thread_getpid();
msg_t m;
while (msg_receive(&m)) {
printf("display_thread got a message\n");
const char *name = uber_get_name(dest);
lcd1602d_printstr(&lcd, 0, 1, name);
int i;
for (i=strlen(name); i<10; i++){
lcd1602d_printstr(&lcd, i, 1, " ");
}
}
return NULL;
}
#ifdef ENABLE_NRF_COMM
char rx_handler_stack[THREAD_STACKSIZE_MAIN];
/* RX handler that waits for a message from the ISR */
@ -201,6 +378,10 @@ void *nrf24l01p_rx_handler(void *arg)
/* puts(""); */
uber_dump_frame(&frame);
char buf[256] = {0};
uber_get_frame(&frame, buf);
printf("lcd rx:%p\n", &lcd);
lcd1602d_printstr(&lcd, 0, 0, buf);
break;
default:
@ -214,6 +395,7 @@ void *nrf24l01p_rx_handler(void *arg)
return NULL;
}
/**
* @init transceiver
*/
@ -350,6 +532,14 @@ int cmd_uber_setup(int argc, char **argv)
return 1;
}
/* create thread that display msg */
if (thread_create(
display_handler_stack, sizeof(display_handler_stack), THREAD_PRIORITY_MAIN - 1, 0,
display_thread, 0, "display_thread") < 0) {
puts("Error in thread_create");
return 1;
}
@ -619,22 +809,34 @@ int cmd_print_regs(int argc, char **argv)
return 0;
}
#endif
static int dest = 0;
void test_cb(void * bid){
int id = *(int*)bid;
printf ("in cb %d\n", id);
static char dest_str[10] = {0};
// static char dest_str[10] = {0};
static char *argv[] = {"", "4", dest_str , "1"};
(void)argv;
switch (id){
case 1:
dest = (dest +1) % 9;
dest = (dest +1 ) % 9;
if (!dest) {
// skip 0, it is invalid
dest = 1;
}
printf("dest %d\n", dest != 8 ? dest : 0xFF);
sprintf(dest_str, "%d", dest != 8 ? dest : 0xFF);
printf("lcd cb:%p\n", &lcd);
// lcd1602d_printstr(&lcd, 0, 1, dest_str);
if (display_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = 0;
m.content.ptr = NULL;
msg_send_int(&m, display_pid);
}
return;
break;
case 2:
break;
@ -642,6 +844,10 @@ void test_cb(void * bid){
return;
}
sprintf(dest_str, "%d", dest != 8 ? dest : 0xFF);
dest_str[9] = 0;
#ifdef SPI_NUMOF
if (sender_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = RCV_PKT_NRF24L01P;
@ -649,29 +855,92 @@ void test_cb(void * bid){
/* transmit more things here ? */
msg_send_int(&m, sender_pid);
}
#endif
printf("exit cb\n");
//cmd_send(4, argv);
}
#ifdef ADC_NUMOF
static int res_ladder_val(adc_t adc, int channel){
int sample = adc_sample(adc, channel);
const int max_v = 4095;
int j;
int but_state = 0;
// printf("%d\n", sample);
for (j=1; j<=4; j++){
// printf("[%d-%d > %d?", sample, max_v/(1<<j), -(max_v/(1<<(j+2))));
if (sample - max_v/(1<<j) > -max_v/(32) /* -(max_v/(1<<(j+2))) */ /* -4095/(j*(j+1)) */){
// printf("%d Test ok /", j);
sample -= max_v/(1<<j);
but_state |= 1<<(j-1);
}
}
return but_state;
}
#endif
int main(void)
{
puts("Uber\n");
puts("Uber\n");
gpio_t b1 = GPIO_PIN(PORT_F, 4);
int b1_v = 1, b2_v = 2;
gpio_init_int(b1, GPIO_PULLUP, GPIO_FALLING, test_cb, &b1_v);
gpio_t b2 = GPIO_PIN(PORT_F, 0);
gpio_init_int(b2, GPIO_PULLUP, GPIO_FALLING, test_cb, &b2_v);
#ifdef ADC_NUMOF
adc_init(ADC_0, 10);
#endif
lcd1602d_init_lcd(&lcd);
// lcd1602d_setCursor(&lcd, 0,0);
printf("lcd:%p\n", &lcd);
/* lcd1602d_printstr(&lcd, 0,0,"Bojr"); */
/* lcd1602d_printstr(&lcd, 3,1,"Bloop"); */
gpio_t b1 = GPIO_PIN(PORT_F, 4);
int b1_v = 1, b2_v = 2;
gpio_init_int(b1, GPIO_PULLUP, GPIO_FALLING, test_cb, &b1_v);
gpio_t b2 = GPIO_PIN(PORT_F, 0);
gpio_init_int(b2, GPIO_PULLUP, GPIO_FALLING, test_cb, &b2_v);
gpio_init(led, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_clear(led);
//char line_buf[SHELL_DEFAULT_BUFSIZE];
#ifdef SPI_NUMOF
cmd_uber_setup(0, NULL);
#endif
//shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
gpio_init(led, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_clear(led);
/* gpio_init_int(b1, GPIO_PULLUP, GPIO_BOTH, rotary_cb, NULL); */
/* gpio_init(b2, GPIO_DIR_IN, GPIO_PULLUP); */
//char line_buf[SHELL_DEFAULT_BUFSIZE];
cmd_uber_setup(0, NULL);
//shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
while(1){
thread_yield();
#ifdef ADC_NUMOF
int button_state = res_ladder_val(ADC_0, 2);
#endif
while(1){
#ifdef ADC_NUMOF
int new_button_state = res_ladder_val(ADC_0, 2);
if (new_button_state != button_state){
button_state = new_button_state;
printf("%d-%d-%d-%d\n", new_button_state & 0x8 ? 1 : 0,
new_button_state & 0x4 ? 1 : 0,
new_button_state & 0x2 ? 1 : 0,
new_button_state & 0x1 ? 1 : 0);
dest = new_button_state;
if (display_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = 0;
m.content.ptr = NULL;
msg_send_int(&m, display_pid);
}
}
return 0;
#endif
xtimer_usleep(10000);
thread_yield();
}
return 0;
}

53
uberframe.c

@ -18,25 +18,64 @@ static const char *uber_events[] = {
static const char *uber_ids[] = {
"INVALID",
"BenjM",
"Clém",
"Jérôme",
"Clem",
"Jérome",
"Marc",
"GuillaumeS",
"Dams",
"GuillaumeL",
[0xFF] "ALL"
"glager",
[8 ... 0xFE]="none",
[0xFF]="ALL"
};
const char* uber_get_name(uint8_t id){
if(id > (sizeof(uber_ids)/sizeof(char*)))
return "INVALID!";
return uber_ids[id > sizeof(uber_ids)/sizeof(char*) ? 0xFF : id];
}
void uber_get_frame(radiohead_frame_t *f, char* buf){
const char *src = (f->frame.header.src < sizeof(uber_ids)/sizeof(char*)) ?
uber_ids[f->frame.header.src] :
"INV";
const char *dst = (f->frame.header.dst < sizeof(uber_ids)/sizeof(char*)) ?
uber_ids[f->frame.header.dst] :
"INV";
const char *t = (f->frame.header.type < sizeof(uber_events)/sizeof(char*)) ?
uber_events[f->frame.header.type] :
"INV";
sprintf (buf,
"s:%s d:%s t:%s",
src,
dst,
t);
}
int uber_dump_frame(radiohead_frame_t *f){
const char *src = f->frame.header.src < (sizeof(uber_ids)/sizeof(char*)) ?
uber_ids[f->frame.header.src] :
"INV";
const char *dst = f->frame.header.dst < (sizeof(uber_ids)/sizeof(char*)) ?
uber_ids[f->frame.header.dst] :
"INV";
const char *t = f->frame.header.type < (sizeof(uber_events)/sizeof(char*)) ?
uber_events[f->frame.header.type] :
"INV";
printf ("discard : %" PRIx16 ", %" PRIx16 "\n", f->radiohead_src, f->radiohead_dst);
printf ("flags : %x\n", f->frame.header.flags);
printf ("src: %x (%s)\n", f->frame.header.src, uber_ids[f->frame.header.src]);
printf ("src: %x (%s)\n", f->frame.header.src, src);
printf ("dst: %x (%s)\n", f->frame.header.dst, uber_ids[f->frame.header.dst]);
printf ("dst: %x (%s)\n", f->frame.header.dst, dst);
printf ("type: %x (%s)\n", f->frame.header.type, uber_events[f->frame.header.type]);
printf ("type: %x (%s)\n", f->frame.header.type, t);
printf ("pl_sz: %x\n", f->frame.header.payload_sz);
return 0;
}

2
uberframe.h

@ -28,3 +28,5 @@ typedef struct __attribute__((packed)) {
int uber_dump_frame(radiohead_frame_t *f);
size_t uber_get_frame_size(radiohead_frame_t *t);
void uber_get_frame(radiohead_frame_t *f, char* buf);
const char* uber_get_name(uint8_t id);

Loading…
Cancel
Save