30 #include <libopencmsis/core_cm3.h> 31 #include <libopencm3/cm3/nvic.h> 32 #include <libopencm3/stm32/rcc.h> 33 #include <libopencm3/stm32/gpio.h> 34 #include <libopencm3/stm32/timer.h> 35 #include <libopencm3/stm32/exti.h> 44 #define ONEWIRE_SLAVE_TIMER 2 52 #define ONEWIRE_SLAVE_PORT A 53 #define ONEWIRE_SLAVE_PIN 4 57 static volatile enum { 94 if (NULL==data || 0==length) {
99 for (uint8_t i=0; i<length; i++) {
101 for (uint8_t b=0; b<8; b++) {
150 rcc_periph_clock_enable(RCC_AFIO);
159 if (NULL==data || 0==size) {
162 if (UINT32_MAX/8<size) {
178 if (NULL==data || 0==size) {
184 if (UINT32_MAX/8<size) {
296 static uint8_t rom_code_byte;
#define TIM_ISR(x)
get interrupt service routine for timer base on TIM identifier
waiting before sending the presence pulse
slave is reading function command bits
static volatile uint8_t bits_buffer
buffer for the incoming bits (up to one byte)
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
bool onewire_slave_function_read(uint8_t *data, size_t size)
read data from master
sending the presence pulse
volatile bool onewire_slave_function_code_received
set when a function command code has been received
slave is sending ROM code in response to ROM command READ ROM
#define NVIC_TIM_IRQ(x)
get NVIC IRQ for timer base on TIM identifier
#define NVIC_EXTI_IRQ(x)
get NVIC IRQ for external interrupt base on external interrupt/pin
static enum @1 onewire_slave_state
state of 1-Wire communication
global definitions and methods (API)
#define GPIO(x)
get GPIO based on GPIO identifier
#define ONEWIRE_SLAVE_PORT
GPIO port.
static volatile uint32_t onewire_slave_transfer_bits
number of bits to transfer
#define ONEWIRE_SLAVE_PIN
GPIO pin.
#define RCC_TIM(x)
get RCC for timer based on TIM identifier
master is searching ROM code, slave will send first bit (not negated)
volatile uint8_t onewire_slave_function_code
last function command code received
static uint8_t onewire_slave_crc(uint8_t *data, uint32_t length)
compute CRC for 1-Wire
master is searching ROM code, slave will read selected bit
bool onewire_slave_function_write(const uint8_t *data, size_t size)
write data to master
master is sending ROM code to select slave
#define EXTI(x)
get external interrupt based on pin identifier
master is searching ROM code, slave will send first bit (not negated)
volatile bool onewire_slave_transfer_complete
set when data read/write transfer has been completed
to count the number of possible states
void onewire_slave_setup(uint8_t family, uint64_t serial)
setup 1-wire peripheral
static volatile uint32_t bits_bit
number of incoming bits
#define EXTI_ISR(x)
get interrupt service routine for timer base on external interrupt/pin
static uint8_t onewire_slave_rom_code[8]
slave ROM code
slave is reading ROM command bits
#define LENGTH(x)
get the length of an array
#define TIM(x)
get TIM based on TIM identifier
library for 1-wire protocol as slave (API)
reset pulse has been detected
static volatile uint8_t * onewire_slave_transfer_data
data to transfer (read or write)
#define ONEWIRE_SLAVE_TIMER
timer ID
waiting for user to provide data to transfer