27 #include <libopencm3/stm32/rcc.h> 28 #include <libopencm3/stm32/gpio.h> 29 #include <libopencm3/stm32/timer.h> 42 BUSVOODOO_ONEWIRE_SETTING_NONE,
43 BUSVOODOO_ONEWIRE_SETTING_PULLUP,
44 BUSVOODOO_ONEWIRE_SETTING_POWER,
45 BUSVOODOO_ONEWIRE_SETTING_DONE,
59 bool complete =
false;
64 case BUSVOODOO_ONEWIRE_SETTING_NONE:
66 printf(
"1) use embedded pull-up resistor (2kO)\n");
67 printf(
"2) use external pull-up resistor\n");
71 case BUSVOODOO_ONEWIRE_SETTING_PULLUP:
72 if (NULL==line || 0==strlen(line)) {
74 }
else if (1==strlen(line)) {
75 uint8_t pullup = atoi(line);
76 if (1==pullup || 2==pullup) {
82 printf(
"1) don't drive 1-wire data line (target uses external or parasitic power)\n");
83 printf(
"2) power 1-wire data line at 3.3V when not communicating (not multi-master compatible)\n");
88 case BUSVOODOO_ONEWIRE_SETTING_POWER:
89 if (NULL==line || 0==strlen(line)) {
91 }
else if (1==strlen(line)) {
92 uint8_t power = atoi(line);
93 if (1==power || 2==power) {
107 printf(
"use LV to set pull-up voltage\n");
113 const char* pinout_io[10] = {
"GND",
"5V",
"3V3",
"LV", NULL,
"1WR", NULL, NULL, NULL, NULL};
118 const char* pinout_rscan[5] = {
"HV", NULL, NULL, NULL, NULL};
140 printf(
"write: 0x%02x", value);
155 printf(
"read: 0x%02x%s\n", data, error ?
"" :
" (error)");
174 uint32_t length = strlen(action);
175 if (NULL==action || 0==length) {
179 if (1==length &&
'r'==action[0]) {
183 for (uint32_t i=0; i<repetition; i++) {
186 }
else if (1==length &&
'['==action[0]) {
194 printf(
"WARNING: data line does not seem to be pulled up\n");
196 printf(
"start transaction: ");
198 printf(
"slave presence %sdetected\n", presence ?
"" :
"not ");
199 }
else if (1==length &&
']'==action[0]) {
207 }
else if (1==length &&
'u'==action[0]) {
211 printf(
"wait for %u us\n", repetition);
213 }
else if (1==length &&
'm'==action[0]) {
217 printf(
"wait for %u ms\n", repetition);
219 }
else if (
'0'==action[0]) {
224 for (uint32_t i=0; i<repetition; i++) {
227 }
else if (
'x'==action[1] ||
'b'==action[1]) {
229 }
else if (action[1]>=
'0' && action[1]<=
'9') {
234 }
else if (
'x'==action[0] && length>1) {
235 for (uint32_t i=1; i<length; i++) {
236 if (!((action[i]>=
'0' && action[i]<=
'9') || (action[i]>=
'a' && action[i]<=
'f') || (action[i]>=
'A' && action[i]<=
'F'))) {
243 uint32_t value = strtol(&action[1], NULL, 16);
244 for (uint32_t i=0; i<repetition; i++) {
247 }
else if (
'b'==action[0] && length>1) {
248 for (uint32_t i=1; i<length; i++) {
249 if (action[i]<
'0' || action[i]>
'1') {
256 uint32_t value = strtol(&action[1], NULL, 2);
257 for (uint32_t i=0; i<repetition; i++) {
260 }
else if (action[0]>=
'1' && action[0]<=
'9') {
261 for (uint32_t i=1; i<length; i++) {
262 if (action[i]<
'0' || action[i]>
'9') {
269 uint32_t value = strtol(&action[0], NULL, 10);
270 for (uint32_t i=0; i<repetition; i++) {
273 }
else if (length>=2 && (
'"'==action[0] ||
'\''==action[0]) && (action[length-1]==action[0])) {
277 for (uint32_t r=0; r<repetition; r++) {
278 for (uint32_t i=1; i<length-1; i++) {
296 if (NULL==argument || 0==strlen(argument)) {
297 printf(
"available actions (separated by space or ,):\n");
298 printf(
"[\tstart transaction: send reset pulse and detect slave presence\n");
300 printf(
"0\twrite decimal byte\n");
301 printf(
"0x0\twrite hexadecimal byte\n");
302 printf(
"0b0\twrite binary byte\n");
303 printf(
"\"a\"/'a'\twrite ASCII characters\n");
305 printf(
"u/m\twait 1 us/ms\n");
306 printf(
":n\trepeat action n times\n");
310 char* copy = calloc(strlen(argument)+1,
sizeof(
char));
314 strncpy(copy, argument, strlen(argument)+1);
317 printf(
"malformed action(s)\n");
330 if (argument && 0==strcmp(argument,
"alarm")) {
337 printf(
"WARNING: data line does not seem to be pulled up\n");
340 printf(
"slave presence %sdetected\n", presence ?
"" :
"not ");
344 printf(
"searching ROM codes%s:\n", alarm ?
" with alarm" :
"");
352 printf(
"0x%016X\n", code);
354 }
while (presence && next);
355 printf(
"%U ROM code(s)%s found\n", codes, alarm ?
" with alarm" :
"");
367 .command_description =
"perform protocol actions",
369 .argument_description =
"[actions]",
375 .command_description =
"perform ROM search",
377 .argument_description =
"[alarm]",
384 .description =
"1-Wire",
#define BUSVOODOO_LED_PULSE
recommended duration in ms for pulsing LEDs to show activity
static bool busvoodoo_onewire_action(const char *action, uint32_t repetition, bool perform)
perform 1-wire action
const struct busvoodoo_mode_t busvoodoo_onewire_mode
1-wire mode interface definition
BusVoodoo global definitions and methods (API)
static bool busvoodoo_onewire_embedded_pullup
if embedded pull-up resistors are used
#define ONEWIRE_MASTER_PORT
GPIO port.
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
const char * name
name of the mode (i.e.
void busvoodoo_led_blue_pulse(uint32_t ms)
pulse blue LED for short duration
bool onewire_master_rom_search(uint64_t *code, bool alarm)
send SEARCH ROM command
#define ONEWIRE_MASTER_PIN
GPIO pin.
static void busvoodoo_onewire_rom_search(void *argument)
command to perform ROM search
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
void onewire_master_setup(void)
setup 1-wire peripheral
global definitions and methods (API)
#define GPIO(x)
get GPIO based on GPIO identifier
void sleep_us(uint32_t duration)
go to sleep for some microseconds
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
library for 1-wire protocol as master (API)
bool onewire_master_write_byte(uint8_t data)
write data byte
void busvoodoo_led_blue_off(void)
switch off blue LED
busvoodoo_onewire_setting_t
mode setup stage
static void busvoodoo_onewire_exit(void)
exit 1-wire mode
static enum busvoodoo_onewire_setting_t busvoodoo_onewire_setting
current mode setup stage
char shortcut
short command code (0 if not available)
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
static void busvoodoo_onewire_command_actions(void *argument)
command to perform actions
char busvoodoo_global_string[64]
shared string buffer, i.e.
size_t snprintf(char *str, size_t size, const char *format,...)
print format string on string or user output
bool busvoodoo_global_actions(char *actions, bool perform, bool(*action_handler)(const char *action, uint32_t repetition, bool perform))
parse and perform actions
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
size_t printf(const char *format,...)
print format string on user output
static bool busvoodoo_onewire_power
time (in ms) between slot to provide power
bool onewire_master_read_byte(uint8_t *data)
read data byte
printing utilities to replace the large printf from the standard library (API)
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
BusVoodoo 1-wire mode (API)
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
static void busvoodoo_onewire_write(uint8_t value)
write to 1-wire
static void busvoodoo_onewire_read(void)
read from 1-wire
#define LENGTH(x)
get the length of an array
static bool busvoodoo_onewire_setup(char **prefix, const char *line)
setup 1-wire mode
void onewire_master_release(void)
release 1-wire peripheral
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
static const struct menu_command_t busvoodoo_onewire_commands[]
1-wire menu commands
BusVoodoo mode interface.
bool onewire_master_reset(void)
send reset pulse