#include "serial.h"
#include "rn42.h"
#include "print.h"
+#include "timer.h"
#include "wait.h"
void rn42_init(void)
{
- // PF7: BT connection control(HiZ: connect, low: disconnect)
// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
+
+ // PF7: BT connection control(high: connect, low: disconnect)
rn42_autoconnect();
+ // PF6: linked(input without pull-up)
+ DDRF &= ~(1<<6);
+ PORTF |= (1<<6);
+
// PF1: RTS(low: allowed to send, high: not allowed)
DDRF &= ~(1<<1);
PORTF &= ~(1<<1);
serial_init();
}
+int16_t rn42_getc(void)
+{
+ return serial_recv2();
+}
+
+char *rn42_gets(uint16_t timeout)
+{
+ static char s[16];
+ uint16_t t = timer_read();
+ uint8_t i = 0;
+ int16_t c;
+ while (i < 15 && timer_elapsed(t) < timeout) {
+ if ((c = rn42_getc()) != -1) {
+ if ((char)c == '\r') continue;
+ if ((char)c == '\n') break;
+ s[i++] = c;
+ }
+ }
+ s[i] = '\0';
+ return s;
+}
+
void rn42_putc(uint8_t c)
{
serial_send(c);
}
+void rn42_puts(char *s)
+{
+ while (*s)
+ serial_send(*s++);
+}
+
bool rn42_autoconnecting(void)
{
// GPIO6 for control connection(high: auto connect, low: disconnect)
PORTD &= ~(1<<5);
}
+bool rn42_linked(void)
+{
+ // RN-42 GPIO2
+ // Hi-Z: Not powered
+ // High: Linked
+ // Low: Connecting
+ return !rn42_rts() && PINF&(1<<6);
+}
+
-static uint8_t keyboard_leds(void) { return 0; }
+static uint8_t leds = 0;
+static uint8_t keyboard_leds(void) { return leds; }
+void rn42_set_leds(uint8_t l) { leds = l; }
static void send_keyboard(report_keyboard_t *report)
{
config_send_consumer
};
-static uint8_t config_keyboard_leds(void) { return 0; }
+static uint8_t config_keyboard_leds(void) { return leds; }
static void config_send_keyboard(report_keyboard_t *report) {}
static void config_send_mouse(report_mouse_t *report) {}
static void config_send_system(uint16_t data) {}