fix(i2c): fix soft I2C driver - ACK polarity, SDA transitions, push-pull mode, timeout, float printf
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
#include <gpio_if.h>
|
||||
|
||||
static const gpio_ops_t* g_gpio_ops = 0;
|
||||
void gpio_register_ops(const gpio_ops_t *ops) {
|
||||
g_gpio_ops = ops;
|
||||
}
|
||||
|
||||
int gpio_if_init(int ch) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->init)
|
||||
return -1;
|
||||
return g_gpio_ops->init(ch);
|
||||
}
|
||||
int gpio_if_write(int ch, int val) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->write)
|
||||
return -1;
|
||||
return g_gpio_ops->write(ch, val);
|
||||
|
||||
}
|
||||
int gpio_if_read(int ch) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->read)
|
||||
return -1;
|
||||
return g_gpio_ops->read(ch);
|
||||
#include <gpio_if.h>
|
||||
|
||||
static const gpio_ops_t* g_gpio_ops = 0;
|
||||
void gpio_register_ops(const gpio_ops_t *ops) {
|
||||
g_gpio_ops = ops;
|
||||
}
|
||||
|
||||
int gpio_if_init(int ch) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->init)
|
||||
return -1;
|
||||
return g_gpio_ops->init(ch);
|
||||
}
|
||||
int gpio_if_write(int ch, int val) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->write)
|
||||
return -1;
|
||||
return g_gpio_ops->write(ch, val);
|
||||
|
||||
}
|
||||
int gpio_if_read(int ch) {
|
||||
if (!g_gpio_ops || !g_gpio_ops->read)
|
||||
return -1;
|
||||
return g_gpio_ops->read(ch);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
#ifndef __GPIO_IF_H__
|
||||
#define __GPIO_IF_H__
|
||||
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int ch);
|
||||
int (*write)(int ch, int val);
|
||||
int (*read)(int ch);
|
||||
} gpio_ops_t;
|
||||
|
||||
void gpio_register_ops(const gpio_ops_t *ops);
|
||||
|
||||
int gpio_if_init(int ch);
|
||||
int gpio_if_write(int ch, int val);
|
||||
int gpio_if_read(int ch);
|
||||
#endif
|
||||
#ifndef __GPIO_IF_H__
|
||||
#define __GPIO_IF_H__
|
||||
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int ch);
|
||||
int (*write)(int ch, int val);
|
||||
int (*read)(int ch);
|
||||
} gpio_ops_t;
|
||||
|
||||
void gpio_register_ops(const gpio_ops_t *ops);
|
||||
|
||||
int gpio_if_init(int ch);
|
||||
int gpio_if_write(int ch, int val);
|
||||
int gpio_if_read(int ch);
|
||||
#endif
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include "led_if.h"
|
||||
|
||||
static const led_ops_t *g_led_ops = 0;
|
||||
|
||||
void led_register_ops(const led_ops_t *ops)
|
||||
{
|
||||
g_led_ops = ops;
|
||||
}
|
||||
|
||||
int led_if_init(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->init)
|
||||
return -1;
|
||||
return g_led_ops->init(id);
|
||||
}
|
||||
|
||||
int led_if_write(int id, int state)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->write)
|
||||
return -1;
|
||||
return g_led_ops->write(id, state);
|
||||
}
|
||||
|
||||
int led_if_read(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->read)
|
||||
return -1;
|
||||
return g_led_ops->read(id);
|
||||
}
|
||||
|
||||
int led_if_toggle(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->toggle)
|
||||
return -1;
|
||||
return g_led_ops->toggle(id);
|
||||
#include "led_if.h"
|
||||
|
||||
static const led_ops_t *g_led_ops = 0;
|
||||
|
||||
void led_register_ops(const led_ops_t *ops)
|
||||
{
|
||||
g_led_ops = ops;
|
||||
}
|
||||
|
||||
int led_if_init(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->init)
|
||||
return -1;
|
||||
return g_led_ops->init(id);
|
||||
}
|
||||
|
||||
int led_if_write(int id, int state)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->write)
|
||||
return -1;
|
||||
return g_led_ops->write(id, state);
|
||||
}
|
||||
|
||||
int led_if_read(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->read)
|
||||
return -1;
|
||||
return g_led_ops->read(id);
|
||||
}
|
||||
|
||||
int led_if_toggle(int id)
|
||||
{
|
||||
if (!g_led_ops || !g_led_ops->toggle)
|
||||
return -1;
|
||||
return g_led_ops->toggle(id);
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
#ifndef LED_IF_H
|
||||
#define LED_IF_H
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int id);
|
||||
int (*write)(int id, int state);
|
||||
int (*read)(int id);
|
||||
int (*toggle)(int id);
|
||||
} led_ops_t;
|
||||
|
||||
// 注册接口(由HAL调用)
|
||||
void led_register_ops(const led_ops_t *ops);
|
||||
|
||||
// 对上层暴露统一API
|
||||
int led_if_init(int id);
|
||||
int led_if_write(int id, int state);
|
||||
int led_if_read(int id);
|
||||
int led_if_toggle(int id);
|
||||
|
||||
#ifndef LED_IF_H
|
||||
#define LED_IF_H
|
||||
|
||||
typedef struct {
|
||||
int (*init)(int id);
|
||||
int (*write)(int id, int state);
|
||||
int (*read)(int id);
|
||||
int (*toggle)(int id);
|
||||
} led_ops_t;
|
||||
|
||||
// 注册接口(由HAL调用)
|
||||
void led_register_ops(const led_ops_t *ops);
|
||||
|
||||
// 对上层暴露统一API
|
||||
int led_if_init(int id);
|
||||
int led_if_write(int id, int state);
|
||||
int led_if_read(int id);
|
||||
int led_if_toggle(int id);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "soft_i2c_if.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static const soft_i2c_ops_t *g_soft_i2c_ops = 0;
|
||||
|
||||
@@ -41,3 +42,24 @@ int soft_i2c_if_read(int ch, uint16_t dev_addr, uint8_t *data, uint16_t size, ui
|
||||
return -1;
|
||||
return g_soft_i2c_ops->read(ch, dev_addr, data, size, timeout);
|
||||
}
|
||||
|
||||
int soft_i2c_if_start_frame(int ch) {
|
||||
return g_soft_i2c_ops->__start_frame(ch);
|
||||
}
|
||||
|
||||
int soft_i2c_if_send_frame(int ch, uint8_t byte) {
|
||||
return g_soft_i2c_ops->__send_frame(ch, byte);
|
||||
}
|
||||
int soft_i2c_if_wait_ack_frame(int ch) {
|
||||
return g_soft_i2c_ops->__wait_ack_frame(ch);
|
||||
}
|
||||
int soft_i2c_if_stop_frame(int ch) {
|
||||
return g_soft_i2c_ops->__stop_frame(ch);
|
||||
}
|
||||
int soft_i2c_if_read_frame(int ch, int ack) {
|
||||
return g_soft_i2c_ops->__read_frame(ch, ack);
|
||||
}
|
||||
int soft_i2c_if_send_ack_frame(int ch, int ack) {
|
||||
return g_soft_i2c_ops->__send_ack_frame(ch, ack);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ typedef struct {
|
||||
int (*mem_read)(int ch, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_add_size, uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
int (*write)(int ch, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
int (*read)(int ch, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
void (*__start_frame)(int ch);
|
||||
void (*__send_frame)(int ch, uint8_t byte);
|
||||
int (*__start_frame)(int ch);
|
||||
int (*__send_frame)(int ch, uint8_t byte);
|
||||
int (*__wait_ack_frame)(int ch);
|
||||
void (*__stop_frame)(int ch);
|
||||
int (*__stop_frame)(int ch);
|
||||
int (*__read_frame)(int ch, int ack);
|
||||
void (*__send_ack_frame)(int ch, int ack);
|
||||
int (*__send_ack_frame)(int ch, int ack);
|
||||
} soft_i2c_ops_t;
|
||||
|
||||
void soft_i2c_register_ops(const soft_i2c_ops_t *ops);
|
||||
@@ -29,6 +29,13 @@ int soft_i2c_if_mem_write(int ch, uint16_t dev_addr, uint16_t mem_addr, uint16_t
|
||||
int soft_i2c_if_mem_read(int ch, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_add_size, uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
int soft_i2c_if_write(int ch, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
int soft_i2c_if_read(int ch, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout);
|
||||
int soft_i2c_if_start_frame(int ch);
|
||||
int soft_i2c_if_send_frame(int ch, uint8_t byte);
|
||||
int soft_i2c_if_wait_ack_frame(int ch);
|
||||
int soft_i2c_if_stop_frame(int ch);
|
||||
int soft_i2c_if_read_frame(int ch, int ack);
|
||||
int soft_i2c_if_send_ack_frame(int ch, int ack);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user