Compare commits

...

3 Commits

Author SHA1 Message Date
xenia 872c3988bd WIP 1wire 2021-07-25 20:40:03 -04:00
xenia 0a07b1d7e0 make "set mode 0" mean reset to bootloader 2021-07-25 18:45:14 -04:00
xenia 704919713c fix compile error in sump mode 2021-07-25 18:09:48 -04:00
5 changed files with 68 additions and 2 deletions

View File

@ -28,6 +28,8 @@
#ifndef BOARD_H_MOD
#define BOARD_H_MOD
#include <pico/bootrom.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -48,6 +50,9 @@ extern "C" {
#define UART_RX_PIN PICO_DEFAULT_UART_RX_PIN
#endif
// Reset to bootloader
#define bsp_reset_bootloader() reset_usb_boot(0, 0)
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,3 @@
#include <stdio.h>
#include "m_default/1wire.h"

54
src/m_default/1wire.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef _1WIRE_H
#define _1WIRE_H // we're too cool for #pragma once over here?
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
enum onewire_cmd {
// select controller or peripheral, and enable or disable overdrive mode
OW_SET_MODE = 0x00,
// controller
OW_WRITE_READ = 0x01,
OW_READ_ROM = 0x02,
OW_MATCH_ROM = 0x03,
OW_SEARCH_ROM = 0x04,
// peripheral
OW_SET_EMULATION_TYPE = 0x81,
OW_SET_EMULATION_DATA = 0x82,
OW_REPORT_TIMING = 0x83, // 🕵️📈
};
enum onewire_mode {
OWM_CONTROLLER = 0x00,
OWM_CONTROLLER_OD = 0x10,
OWM_PERIPHERAL = 0x01,
OWM_PERIPHERAL_OD = 0x11
};
enum ow_emulation_type {
DS2401 = 0x2401
// TODO: more
};
// low level init (eg, load and configure PIO program on rp2040)
bool ow_bsp_init();
// low level deinit (eg, unload PIO program on rp2040)
bool ow_bsp_deinit();
// write some bytes then read some bytes
bool ow_write_read(bool od, uint8_t* out, size_t out_len, uint8_t* in, size_t in_len);
// read rom (eg for 1w serial numbers / eeproms)
bool ow_read_rom(bool od, uint8_t* in, size_t in_len);
// TODO: match rom
// bool ow_match_rom(...);
// identify all connected devices
bool ow_search_rom(bool od, uint64_t* discovered_devices, size_t max_devices);
// execute an emulation of a 1w peripheral
void ow_run_peripheral_emulation(
bool od, enum ow_emulation_type typ, uint8_t* data, size_t data_len);
#endif

View File

@ -5,6 +5,7 @@
#include "mode.h"
#include "thread.h"
#include "vnd_cfg.h"
#include "../usbstdio.h"
#include "m_sump/bsp-feature.h"

View File

@ -5,10 +5,10 @@
#include <string.h>
#include <tusb.h>
#include "board.h"
#include "info.h"
#include "mode.h"
#include "vnd_cfg.h"
#include "thread.h"
#if CFG_TUD_VENDOR > 0
@ -175,7 +175,10 @@ void vnd_cfg_task(void) {
break;
case cfg_cmd_set_cur_mode:
verbuf[0] = vnd_cfg_read_byte();
if (verbuf[0] == 0 || verbuf[0] >= 0x10 || mode_list[verbuf[0]] == NULL) {
if (verbuf[0] == 0) {
// reset
bsp_reset_bootloader();
} else if (verbuf[0] >= 0x10 || mode_list[verbuf[0]] == NULL) {
vnd_cfg_write_resp(cfg_resp_nosuchmode, 0, NULL);
} else {
// will be handled later so the USB stack won't break, whcih might happen if reconfig would happen now