#include "core/pio.h"
#include "core/iap.h"
#include "lib/stdio.h"
+#include "lib/utils.h"
#include "drivers/i2c.h"
#include "drivers/adc.h"
#include "drivers/serial.h"
#define SELECTED_FREQ FREQ_SEL_36MHz
-#define DEBUG 0
-#if (DEBUG == 1)
+#define DEBUG 1
+#if (DEBUG == 1) /* Send only on prog output */
+ #define debug_printf(...) \
+ uprintf(__VA_ARGS__); \
+
+ #define debug(cond, ...) \
+ if (cond) { \
+ uprintf(UART0, __VA_ARGS__ ); \
+ }
+
+#elif (DEBUG == 2) /* Send on comm port */
#define debug_printf(...) \
gpio_clear(tx_en); \
uprintf(__VA_ARGS__); \
+ serial_flush(UART0); \
gpio_set(tx_en);
#define debug(cond, ...) \
if (cond) { \
gpio_clear(tx_en); \
uprintf(UART0, __VA_ARGS__ ); \
+ serial_flush(UART0); \
gpio_set(tx_en); \
}
-
#else
#define debug_printf(...) ;
#define debug(...) ;
/* Get hold of Tx line */
if (need_config == 1) {
/* Request a new address from host */
+ serial_flush(UART0);
+ /* Do not place any of the following instructions before the flush end */
+ isb();
gpio_clear(tx_en);
- if (serial_send_quickbyte(UART0, 'c') == 0) {
+ if (serial_write(UART0, "$c", 2) == 2) {
addr_req = 1;
need_config = 0;
}
+ /* And wait for fush end before relaesing the line */
+ isb();
+ serial_flush(UART0);
+ isb();
gpio_set(tx_en);
}
if (1) {
char buff[20];
uint16_t* data = (uint16_t*)buff;
-
+ memset(buff, 0, 20);
buff[0] = '#';
buff[1] = address | (got_tsl << 5) | (got_veml << 6) | (got_bme << 7);
data[1] = (uint16_t)htons(raw_humidity);
data[6] = (uint16_t)htons(comp_temp);
data[7] = (uint16_t)htons(humidity);
+ serial_flush(UART0);
+ /* Do not place any of the following instructions before the flush end */
+ isb();
gpio_clear(tx_en);
serial_write(UART0, buff, 20);
+ /* And wait for fush end before relaesing the line */
+ isb();
+ serial_flush(UART0);
+ isb();
gpio_set(tx_en);
}
}