Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
M
Meh-sla Automotive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
3
Snippets
Groups
Projects
Show more breadcrumbs
Karthigai Amutha Ezhilarasu
Meh-sla Automotive
Commits
8d09cf22
Commit
8d09cf22
authored
2 years ago
by
Karthigai Amutha Ezhilarasu
Browse files
Options
Downloads
Patches
Plain Diff
bluetooth command mode working
parent
9ab01cf2
No related branches found
No related tags found
2 merge requests
!16
Bridge board bluetooth
,
!8
Bridge board - sending GPS fake destination
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
projects/bridge_controller/l4_io/Bluetooth/bluetooth.c
+106
-0
106 additions, 0 deletions
projects/bridge_controller/l4_io/Bluetooth/bluetooth.c
projects/bridge_controller/l4_io/Bluetooth/bluetooth.h
+18
-0
18 additions, 0 deletions
projects/bridge_controller/l4_io/Bluetooth/bluetooth.h
with
124 additions
and
0 deletions
projects/bridge_controller/l4_io/Bluetooth/bluetooth.c
0 → 100644
+
106
−
0
View file @
8d09cf22
#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
;
}
This diff is collapsed.
Click to expand it.
projects/bridge_controller/l4_io/Bluetooth/bluetooth.h
0 → 100644
+
18
−
0
View file @
8d09cf22
#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
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment