Clean conditional compilation + rebase

- use if instead of ifdef
- rebase on top of latest upstream RIOT
master
Marc Poulhiès 7 years ago
parent bffbf6abdb
commit a08935022f

@ -11,6 +11,7 @@ USEMODULE += nrf24l01p
USEMODULE += servo
USEMODULE += rotary_encoder
##CFLAGS += -DDEVELHELP=1
# set default device parameters in case they are undefined
NRF_SPI_PORT ?= SPI_0
WS2812_SPI_PORT ?= SPI_1
@ -22,8 +23,8 @@ CFLAGS_OPT = -O3 -Wno-unused
# export parameters
CFLAGS += -DENABLE_RES_LADDER=1
CFLAGS += -DRES_LADDER_ADC=ADC_0
CFLAGS += -DRES_LADDER_CHAN=2
CFLAGS += -DRES_LADDER_ADC_LINE=ADC_LINE\(2\)
##CFLAGS += -DRES_LADDER_CHAN=2
CFLAGS += -DENABLE_LCD=1
@ -44,13 +45,14 @@ CFLAGS += -DENABLE_ROTARY=1
CFLAGS += -DROTARY_PIN2=GPIO_PIN\(PORT_D,6\)
CFLAGS += -DROTARY_PIN1=GPIO_PIN\(PORT_C,7\)
CFLAGS += -DENABLE_ROTARY_BUTTON=1
CFLAGS += -DENABLE_ROTARY_BUTTON=0
CFLAGS += -DROTARY_BUTTON_PIN=GPIO_PIN\(PORT_D,7\)
CFLAGS += -DENABLE_BOARD_SWITCH=1
CFLAGS += -DENABLE_SERVO=1
CFLAGS += -DSERVO_FREQUENCY=50 -DSERVO_RESOLUTION=0xc3500
CFLAGS += -DSERVO_FREQUENCY=50 -DSERVO_RESOLUTION=0xffff
##-DSERVO_RESOLUTION=0xc3500
CFLAGS += -DSERVO_PWM=PWM_2
##CFLAGS += -I$(HOME)/git/ubberFrame

@ -37,8 +37,8 @@
#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);
gpio_init(lcd->rs_pin, GPIO_OUT);
gpio_init(lcd->enable_pin, GPIO_OUT);
lcd->currline = 0;
xtimer_usleep(50000);
@ -193,7 +193,7 @@ void lcd1602d_send(struct lcd_ctx* lcd, uint8_t value, uint8_t mode) {
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);
gpio_init(lcd->data_pins[i], GPIO_OUT);
if ((value >> i) & 0x01)
gpio_set(lcd->data_pins[i]);

160
main.c

@ -1,4 +1,4 @@
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
#ifndef NRF_SPI_PORT
#error "NRF_SPI_PORT not defined"
#endif
@ -48,7 +48,7 @@ static servo_t servo1;
#include <periph/adc.h>
#include "periph_conf.h"
#ifdef ENABLE_LCD
#if ENABLE_LCD
#include "lcd1602d.h"
#endif
@ -66,7 +66,7 @@ mm545x_t mm545p = {0};
#define TEST_RX_MSG 1
#ifdef ENABLE_NRF_COMM
#if 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);
@ -83,18 +83,18 @@ static int cmd_set_dpl(int argc, char **argv);
void printbin(unsigned byte);
void print_register(char reg, int num_bytes);
#ifdef ENABLE_SEND_LED
#if ENABLE_SEND_LED
static gpio_t led = GPIO_PIN(PORT_F, 1);
#endif
static unsigned int display_pid = KERNEL_PID_UNDEF;
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
static nrf24l01p_t nrf24l01p_0;
static unsigned int sender_pid = KERNEL_PID_UNDEF;
#endif
#ifdef ENABLE_LCD
#if ENABLE_LCD
struct lcd_ctx lcd = {
.rs_pin = GPIO_PIN(PORT_E, 5),
.enable_pin = GPIO_PIN(PORT_E,4),
@ -108,7 +108,7 @@ struct lcd_ctx lcd = {
* define some additional shell commands
*/
static const shell_command_t shell_commands[] = {
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
{"setaa", "set auto ack", cmd_set_aa },
{"setchannel", "set channel", cmd_set_channel },
{"status", "get status value", cmd_get_status },
@ -125,7 +125,7 @@ static const shell_command_t shell_commands[] = {
};
// ROTARY
#ifdef ENABLE_ROTARY
#if ENABLE_ROTARY
#include "rotary.h"
@ -276,7 +276,7 @@ void prtbin(unsigned byte)
}
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
/**
* @print register
*/
@ -322,7 +322,7 @@ char display_handler_stack[THREAD_STACKSIZE_MAIN];
static char dest_str[256] = {0};
static int dest = 0;
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
char tx_handler_stack[THREAD_STACKSIZE_MAIN];
/* RX handler that waits for a message from the ISR */
@ -337,11 +337,11 @@ void *nrf24l01p_tx_thread(void *arg){
printf("nrf24l01p_tx got a message\n");
// lcd1602d_printstr(&lcd, 0, 1, dest_str);
#ifdef ENABLE_LCD
#if ENABLE_LCD
lcd1602d_printstr(&lcd, 10, 1, "SEND...");
#endif
cmd_send(4, (char**)m.content.ptr);
#ifdef ENABLE_LCD
#if ENABLE_LCD
lcd1602d_printstr(&lcd, 10, 1, "IDLE ");
#endif
}
@ -354,21 +354,22 @@ void *display_thread(void *arg){
msg_init_queue(msg_q, 1);
display_pid = thread_getpid();
printf("Display thread starting %d\n", display_pid);
msg_t m;
while (msg_receive(&m)) {
printf("display_thread got a message\n");
#ifdef ENABLE_LCD
#if ENABLE_LCD
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, " ");
}
}
#endif
}
return NULL;
}
@ -459,7 +460,7 @@ void *ws2812_thread(void *arg){
}
#endif /* ENABLE_WS2812 */
#ifdef ENABLE_ROTARY
#if ENABLE_ROTARY
char rotary_thread_stack[THREAD_STACKSIZE_MAIN];
rotary_t rotarydev;
@ -468,6 +469,11 @@ void *rotary_thread(void *arg){
msg_t msg_q[1];
msg_init_queue(msg_q, 1);
unsigned int pid = thread_getpid();
#if ENABLE_SERVO
int dir = 0;
#endif
puts("Registering rotary_handler thread...");
rotary_register(&rotarydev, pid);
@ -480,20 +486,39 @@ void *rotary_thread(void *arg){
case ROTARY_EVT:
if (m.content.value == DIR_CW){
puts("DIR CW\n");
#if ENABLE_SERVO
dir=1;
#endif
} else {
puts("DIR CCW\n");
#if ENABLE_SERVO
dir=-1;
#endif
}
break;
default:
break;
}
#if ENABLE_SERVO
if(dir){
current_pulse += (dir * 10);
printf("curr %d\n", current_pulse);
if (current_pulse >= 1000 && current_pulse <= 2000){
// scale back servo value in our range
unsigned long long tmp = MS_TO_SERVO(current_pulse);
printf("Scaled : %lx\n", (unsigned long)tmp);
servo_set(&servo1, tmp);
}
}
#endif
}
return NULL;
}
#endif
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
char rx_handler_stack[THREAD_STACKSIZE_MAIN];
/* RX handler that waits for a message from the ISR */
@ -541,10 +566,12 @@ void *nrf24l01p_rx_handler(void *arg)
char buf[256] = {0};
uber_get_frame(&frame, buf);
#ifdef ENABLE_LCD
#if ENABLE_LCD
printf("lcd rx:%p\n", &lcd);
lcd1602d_printstr(&lcd, 0, 0, buf);
#endif
#if ENABLE_WS2812
if (ws2812_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = WS2812_NEW_RFMSG;
@ -702,16 +729,6 @@ 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;
}
/* setup device as receiver */
if (nrf24l01p_set_rxmode(&nrf24l01p_0) < 0) {
@ -729,7 +746,7 @@ int cmd_uber_setup(int argc, char **argv)
*/
int cmd_send(int argc, char **argv)
{
#ifdef ENABLE_SEND_LED
#if ENABLE_SEND_LED
gpio_set(led);
#endif
puts("Send");
@ -797,7 +814,7 @@ int cmd_send(int argc, char **argv)
puts("Error in nrf24l01p_set_rxmode");
return 1;
}
#ifdef ENABLE_SEND_LED
#if ENABLE_SEND_LED
gpio_clear(led);
#endif
return 0;
@ -1001,7 +1018,7 @@ void test_cb(void * bid){
}
printf("dest %d\n", dest != 8 ? dest : 0xFF);
#ifdef ENABLE_LCD
#if ENABLE_LCD
printf("lcd cb:%p\n", &lcd);
// lcd1602d_printstr(&lcd, 0, 1, dest_str);
if (display_pid != KERNEL_PID_UNDEF) {
@ -1024,7 +1041,7 @@ void test_cb(void * bid){
sprintf(dest_str, "%d", dest != 8 ? dest : 0xFF);
dest_str[9] = 0;
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
if (sender_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = RCV_PKT_NRF24L01P;
@ -1038,9 +1055,9 @@ void test_cb(void * bid){
//cmd_send(4, argv);
}
#ifdef ENABLE_RES_LADDER
static int res_ladder_val(adc_t adc, int channel){
int sample = adc_sample(adc, channel);
#if ENABLE_RES_LADDER
static int res_ladder_val(adc_t adc){
int sample = adc_sample(adc, ADC_RES_10BIT);
const int max_v = 4095;
int j;
int but_state = 0;
@ -1066,6 +1083,8 @@ int main(void)
#if ENABLE_SERVO
int r = servo_init(&servo1, SERVO_PWM, 0, MS_TO_SERVO(1000), MS_TO_SERVO(2000));
printf("servo init : %d\n", r);
#else
printf("servo disable\n");
#endif
#if ENABLE_MM5450
@ -1080,16 +1099,26 @@ int main(void)
// mm545x_refreshSegments(&mm545p);
/* gpio_init(GPIO_PIN(PORT_C,5), GPIO_DIR_OUT, GPIO_NOPULL); */
/* gpio_set(GPIO_PIN(PORT_C,5)); */
#else
printf("mm5450 disable\n");
#endif
/* 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;
}
#ifdef ENABLE_LCD
#if ENABLE_LCD
lcd1602d_init_lcd(&lcd);
// lcd1602d_setCursor(&lcd, 0,0);
printf("lcd:%p\n", &lcd);
lcd1602d_printstr(&lcd, 0, 0, "STARTING");
#else
printf("lcd disable\n");
#endif
/* lcd1602d_printstr(&lcd, 0,0,"Bojr"); */
@ -1098,35 +1127,48 @@ int main(void)
#if ENABLE_BOARD_SWITCH
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_init_int(b1, GPIO_IN_PU, 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_int(b2, GPIO_IN_PU, GPIO_FALLING, test_cb, &b2_v);
#else
printf("board switch disable\n");
#endif
#if ENABLE_ROTARY_BUTTON
gpio_t rot_pin = ROTARY_BUTTON_PIN;
int rot_but_arg = 1;
gpio_init_int(rot_pin, GPIO_PULLUP, GPIO_BOTH, test_cb, &rot_but_arg);
gpio_init_int(rot_pin, GPIO_IN_PU, GPIO_BOTH, test_cb, &rot_but_arg);
#else
printf("rotary button disable\n");
#endif
#ifdef ENABLE_SEND_LED
#if ENABLE_SEND_LED
gpio_init(led, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_clear(led);
#else
printf("send led disable\n");
#endif
//char line_buf[SHELL_DEFAULT_BUFSIZE];
#ifdef ENABLE_NRF_COMM
#if ENABLE_NRF_COMM
cmd_uber_setup(0, NULL);
#else
printf("nrf24 disable\n");
#endif
puts("HEYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n");
//shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
#ifdef ENABLE_ROTARY
#if ENABLE_ROTARY
#if 0
gpio_init_int(ROTARY_PIN1, GPIO_PULLUP, GPIO_BOTH, rotary_cb, NULL);
gpio_init_int(ROTARY_PIN2, GPIO_PULLUP, GPIO_BOTH, rotary_cb, NULL); //GPIO_DIR_IN, GPIO_PULLUP);
gpio_init_int(ROTARY_PIN1, GPIO_IN_PU, GPIO_BOTH, rotary_cb, NULL);
gpio_init_int(ROTARY_PIN2, GPIO_IN_PU, GPIO_BOTH, rotary_cb, NULL); //GPIO_DIR_IN, GPIO_PULLUP);
#else
printf("Init rotary encoder\n");
rotary_init(&rotarydev, ROTARY_PIN1, ROTARY_PIN2);
if (thread_create(
@ -1137,13 +1179,19 @@ int main(void)
}
#endif
#endif
#else
printf("rotary disable\n");
#ifdef ENABLE_RES_LADDER
adc_init(RES_LADDER_ADC, 10);
int button_state = res_ladder_val(RES_LADDER_ADC, RES_LADDER_CHAN);
#endif
#if ENABLE_RES_LADDER
adc_init(RES_LADDER_ADC_LINE);//, 10);
int button_state = res_ladder_val(RES_LADDER_ADC_LINE);
#else
printf("res ladder (adc) disable\n");
#endif
#if ENABLE_WS2812
if (thread_create(
ws2812_thread_stack, sizeof(ws2812_thread_stack), THREAD_PRIORITY_MAIN - 1, 0,
@ -1151,6 +1199,9 @@ int main(void)
puts("Error in thread_create");
return 1;
}
#else
printf("ws2812 disable\n");
#endif
// endless loop start
@ -1210,8 +1261,8 @@ int main(void)
}
#endif
#ifdef ENABLE_RES_LADDER
int new_button_state = res_ladder_val(RES_LADDER_ADC, RES_LADDER_CHAN);
#if ENABLE_RES_LADDER
int new_button_state = res_ladder_val(RES_LADDER_ADC_LINE);
if (new_button_state != button_state){
printf("%d-%d-%d-%d\n", new_button_state & 0x8 ? 1 : 0,
@ -1229,13 +1280,16 @@ int main(void)
msg_send_int(&m, display_pid);
}
#if ENABLE_WS2812
if ((new_button_state & 0x8) != (button_state & 0x8) &&
ws2812_pid != KERNEL_PID_UNDEF) {
msg_t m;
m.type = WS2812_BUTTON_STATE;
m.content.value = new_button_state & 0x8;
msg_send_int(&m, ws2812_pid);
}
#endif
button_state = new_button_state;
}

@ -65,8 +65,8 @@ int mm545x_init(mm545x_t *mm, gpio_t clock_pin, gpio_t data_pin){
mm->clock_pin = clock_pin;
mm->data_pin = data_pin;
gpio_init(clock_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(data_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(clock_pin, GPIO_OUT);
gpio_init(data_pin, GPIO_OUT);
gpio_clear(clock_pin);
gpio_clear(data_pin);

Loading…
Cancel
Save