|
|
|
|
#ifndef OWI_H
|
|
|
|
|
#define OWI_H
|
|
|
|
|
|
|
|
|
|
#include "r_cg_macrodriver.h"
|
|
|
|
|
#include "r_cg_serial.h"
|
|
|
|
|
#include "r_cg_port.h"
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* OWI GPIO: P70 (P7.0) + HW Open-Drain (POM7.0)
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
#define OWI_PORT_P P7 /* port data (read/write latch) */
|
|
|
|
|
#define OWI_PORT_PM PM7 /* port mode (1=input, 0=output) */
|
|
|
|
|
#define OWI_PORT_PU PU7 /* pull-up enable */
|
|
|
|
|
#define OWI_PORT_POM POM7 /* open-drain enable */
|
|
|
|
|
|
|
|
|
|
/* P70 = bit0 */
|
|
|
|
|
#define OWI_PIN_MASK (1u << 0)
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Timing
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
#define OWI_BIT_PERIOD_US 100u
|
|
|
|
|
#define TBIT OWI_BIT_PERIOD_US
|
|
|
|
|
#define TLOW_0 (TBIT * 0.75)
|
|
|
|
|
#define TLOW_1 (TBIT * 0.25)
|
|
|
|
|
#define TSTOP_LOW (TBIT * 2)
|
|
|
|
|
#define TIDLE (TBIT * 3)
|
|
|
|
|
#define TSTART_HOLD 50u
|
|
|
|
|
#define SECURE_HIGH 250u
|
|
|
|
|
#define SECURE_TOGGLE_COUNT 3u
|
|
|
|
|
#define SECURE_TOGGLE_LOW 40u
|
|
|
|
|
#define SECURE_TOGGLE_HIGH 60u
|
|
|
|
|
|
|
|
|
|
#ifndef RAM_BYTES
|
|
|
|
|
#define RAM_BYTES 3
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define OWI_IO_MAX_BYTES 64u
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t ok;
|
|
|
|
|
uint8_t timeout;
|
|
|
|
|
uint16_t read_len;
|
|
|
|
|
uint8_t data[OWI_IO_MAX_BYTES];
|
|
|
|
|
uint16_t timeout_byte_index;
|
|
|
|
|
uint8_t timeout_bit_index;
|
|
|
|
|
} owi_io_result_t;
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* API
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
|
|
|
|
|
void GPIO_Clear(void);
|
|
|
|
|
void GPIO_Input(void);
|
|
|
|
|
int GPIO_Read(void);
|
|
|
|
|
|
|
|
|
|
void OWI_Init(uint32_t bit_time_us);
|
|
|
|
|
void OWI_Start(void);
|
|
|
|
|
void OWI_Stop(void);
|
|
|
|
|
void OWI_SecureStop(void);
|
|
|
|
|
|
|
|
|
|
void OWI_WriteBit(int bit);
|
|
|
|
|
void OWI_WriteByte(uint8_t data);
|
|
|
|
|
uint8_t OWI_ReadBit(void);
|
|
|
|
|
uint8_t OWI_ReadByte(void);
|
|
|
|
|
|
|
|
|
|
void OWI_T_ReadBytesAndPrint(int length);
|
|
|
|
|
void OWI_ReadBytesAndPrint(int length, uint8_t id);
|
|
|
|
|
|
|
|
|
|
void OWI_T_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
|
|
|
|
|
void OWI_CommandMode (const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
|
|
|
|
|
void OWI_A_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
|
|
|
|
|
|
|
|
|
|
void OWI_T_CommandModeRaw(const uint8_t *tx_data, uint8_t tx_len, uint8_t id, owi_io_result_t *r);
|
|
|
|
|
void OWI_CommandModeRaw (const uint8_t *tx_data, uint8_t tx_len, uint8_t id, owi_io_result_t *r);
|
|
|
|
|
void OWI_ReadBytesRaw (int length, uint8_t id, owi_io_result_t *r);
|
|
|
|
|
|
|
|
|
|
void OWI_disable(void);
|
|
|
|
|
void GPIO_ForceHighKick(void);
|
|
|
|
|
|
|
|
|
|
uint8_t OWI_HasTimeout(void);
|
|
|
|
|
void OWI_ClearTimeout(void);
|
|
|
|
|
uint16_t OWI_GetLastTimeoutByteIndex(void);
|
|
|
|
|
uint8_t OWI_GetLastTimeoutBitIndex(void);
|
|
|
|
|
|
|
|
|
|
#endif /* OWI_H */
|