{ LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG },
{ LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG },
{ LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG },
+ /* GPIO */
+ { LPC_GPIO_0_0, LPC_IO_DIGITAL },
+ { LPC_GPIO_0_23, LPC_IO_DIGITAL },
+ { LPC_GPIO_0_24, LPC_IO_DIGITAL },
ARRAY_LAST_PIO,
};
const struct pio cc1101_gdo0 = LPC_GPIO_0_6;
const struct pio cc1101_gdo2 = LPC_GPIO_0_7;
+const struct pio move_detect = LPC_GPIO_0_0;
const struct pio temp_alert = LPC_GPIO_0_3;
+const struct pio move_led_green = LPC_GPIO_0_24;
+const struct pio move_led_red = LPC_GPIO_0_23;
+
const struct pio status_led_green = LPC_GPIO_0_28;
const struct pio status_led_red = LPC_GPIO_0_29;
#define ADC_EXT2 LPC_ADC(2)
/***************************************************************************** */
+const struct wdt_config wdconf = {
+ .clk_sel = WDT_CLK_IRC,
+ .intr_mode_only = 0,
+ .nb_clk = 0x03FFFFFF, /* 0x3FF to 0x03FFFFFF */
+};
+
void system_init()
{
- /* Stop the watchdog */
- startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */
+ /* Configure the watchdog */
+ watchdog_config(&wdconf);
system_set_default_power_state();
clock_config(SELECTED_FREQ);
set_pins(common_pins);
}
}
-void bme_display(int uart_num, uint32_t* pressure, uint32_t* temp, uint16_t* humidity)
+void bme_display(int uart_num, uint32_t* pressure, int32_t* temp, uint16_t* humidity)
{
int ret = 0;
}
+/******************************************************************************/
+/* Movement detector */
+static volatile int move_detected = 0;
+void mdet_callback(uint32_t gpio)
+{
+ move_detected = 1;
+ if (gpio_read(move_detect) == 0) {
+ gpio_set(move_led_green);
+ gpio_clear(move_led_red);
+ } else {
+ gpio_set(move_led_red);
+ gpio_clear(move_led_green);
+ }
+}
+
+int mdet_config(int uart_num)
+{
+ set_gpio_callback(mdet_callback, &move_detect, EDGES_BOTH);
+ config_gpio(&move_led_red, 0, GPIO_DIR_OUT, 0);
+ config_gpio(&move_led_green, 0, GPIO_DIR_OUT, 0);
+ return 0;
+}
+
/******************************************************************************/
/* RF Communication */
bme_config(UART0);
uv_config(UART0);
lux_config(UART0);
+ mdet_config(UART0);
/* Add periodic handler */
add_systick_callback(periodic_display, 1000);
adc_start_convertion_once(ADC_VBAT, LPC_ADC_SEQ(0), 0);
/* Tell we are alive :) */
- chenillard(250);
+ watchdog_feed();
+ chenillard(100);
+
+ /* Move detected ! */
+ if (move_detected == 1) {
+ /* FIXME : Send info on RF */
+ memcpy((void*)cc_tx_buff, "Move detected\n", 14);
+ cc_ptr = 14;
+ cc_tx = 1;
+ uprintf(UART0, "Move detected\n");
+ }
/* RF */
if (cc_tx == 1) {
/* Display */
if (update_display == 1) {
uint16_t uv = 0, ir = 0, humidity = 0;
- uint32_t pressure = 0, temp = 0, lux = 0;
+ uint32_t pressure = 0, lux = 0;
+ int32_t temp = 0;
int deci_degrees = 0;
char data[20];
}
update_display = 0;
}
+
+ if (move_detected == 1) {
+ move_detected = 0;
+ }
}
return 0;
}