Skip to content
Snippets Groups Projects
Commit 8d09cf22 authored by Karthigai Amutha Ezhilarasu's avatar Karthigai Amutha Ezhilarasu
Browse files

bluetooth command mode working

parent 9ab01cf2
No related branches found
No related tags found
2 merge requests!16Bridge board bluetooth,!8Bridge board - sending GPS fake destination
#include "bluetooth.h"
#include "gpio.h"
#include "uart.h"
#include <stdio.h>
#include <string.h>
static const uart_e bt_module_uart_port = UART__3;
/**
* Need room for NULL terminator which the module does
* not send over UART. Therefore, we have to put it
* ourself.
*/
static const int max_received_data_in_bytes = 255;
/************************* */
/* TYPEDEFS/ENUMS */
/************************* */
typedef enum { bt_data_mode, bt_command_mode } bt_mode_e;
/***************************** */
/* STATIC FUNCTIONS */
/***************************** */
static void send_command_terminating_characters(void) {
uart__put(bt_module_uart_port, '\r', portMAX_DELAY);
uart__put(bt_module_uart_port, '\n', portMAX_DELAY);
}
static void bt_set_mode(bt_mode_e mode) {
if (mode == bt_command_mode) {
gpio__set(bt_pin__mod);
} else {
gpio__reset(bt_pin__mod);
}
}
static bool bt_setup_commands(void) {
/**
* use bt_module__send_command() to perform necessary
* setup commands such as beacon setup, GAP config, etc.
*/
bool command_send_failure = false;
/** Send commands here */
return command_send_failure;
}
/***************************** */
/* PUBLIC FUNCTIONS */
/***************************** */
/**
* Set up GPIO pins
* - CTS, RTS (optional)
* Init UART at 9600 bps to match BT module
*
* NOTE: If it turns out we need to toggle between UART
* and CMD mode, we need to initially set it to CMD mode
*/
void bt_module__init(void) {
gpio__construct_with_function(GPIO__PORT_4, 28, GPIO__FUNCTION_2);
gpio__construct_with_function(GPIO__PORT_4, 29, GPIO__FUNCTION_2);
uart__init(bt_module_uart_port, clock__get_peripheral_clock_hz(), 9600);
QueueHandle_t rxq = xQueueCreate(255, sizeof(char));
QueueHandle_t txq = xQueueCreate(128, sizeof(char));
uart__enable_queues(bt_module_uart_port, txq, rxq);
bt_pin__mod = gpio__construct_as_output(GPIO__PORT_0, 15);
bt_pin__cts = gpio__construct_as_output(GPIO__PORT_0, 18);
bt_pin__rts = gpio__construct_as_input(GPIO__PORT_2, 9);
gpio__reset(bt_pin__cts);
bt_set_mode(bt_command_mode);
/**
* Eventually need to configure beaconing
*/
// bt_setup_commands();
}
void bt_module__send_command(char *cmd_string) {
bt_set_mode(bt_command_mode);
for (int i = 0; i < strlen(cmd_string); i++) {
uart__put(bt_module_uart_port, cmd_string[i], portMAX_DELAY);
}
send_command_terminating_characters();
// bt_set_mode(bt_data_mode);
}
bool bt_module__recv_data(char *recv_data_ptr) {
bool transmission_successful;
int i = 0;
while (i < max_received_data_in_bytes) {
char incoming_byte = '\0';
if (uart__get(bt_module_uart_port, &incoming_byte, 1000)) {
recv_data_ptr[i++] = incoming_byte;
if (incoming_byte == '\r' || incoming_byte == '\n') {
recv_data_ptr[i] = '\0';
transmission_successful = true;
break;
}
} else {
transmission_successful = false;
}
}
return transmission_successful;
}
#pragma once
#include "gpio.h"
#include <stdbool.h>
/**
* Set up GPIO pins
* - TX, RX, CTS, RTS (optional)
* Init UART at 9600 bps to match BT module
*/
gpio_s bt_pin__cts;
gpio_s bt_pin__rts;
gpio_s bt_pin__mod;
void bt_module__init(void);
void bt_module__send_command(char *cmd_string);
bool bt_module__recv_data(char *recv_data_ptr);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment