1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/openLuat-luatos-soc-air101

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
luat_i2c_air101.c 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Dozingfiretruck Отправлено 2 лет назад c416de3
#include "luat_base.h"
#include "luat_i2c.h"
#include "wm_include.h"
#include "wm_i2c.h"
#include <string.h>
#include "wm_gpio_afsel.h"
#define LUAT_LOG_TAG "i2c"
#include "luat_log.h"
int luat_i2c_exist(int id) {
return id == 0;
}
int luat_i2c_setup(int id, int speed) {
//if (luat_i2c_exist(id) != 0) return -1;
if (speed == 0)
speed = 100 * 1000; // SLOW
else if (speed == 1)
speed = 400 * 1000; // FAST
wm_i2c_scl_config(WM_IO_PA_01);
wm_i2c_sda_config(WM_IO_PA_04);
tls_i2c_init(speed);
return 0;
}
int luat_i2c_close(int id) {
return 0;
}
int luat_i2c_send(int id, int addr, void* buff, size_t len , uint8_t stop) {
tls_i2c_write_byte(addr << 1, 1);
if(WM_FAILED == tls_i2c_wait_ack())
return -1;
for (size_t i = 0; i < len; i++){
tls_i2c_write_byte(((u8*)buff)[i], 0);
if(WM_FAILED == tls_i2c_wait_ack())
return -1;
}
if (stop){
tls_i2c_stop();
}
return 0;
}
int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
tls_i2c_write_byte((addr << 1) + 1, 1);
if(WM_FAILED == tls_i2c_wait_ack())
return -1;
if (len < 1)
return -1;
else if (len == 1){
((u8*)buff)[0] = tls_i2c_read_byte(0, 1);
}else {
for (size_t i = 0; i < len; i++){
if (i == 0)
((u8*)buff)[i] = tls_i2c_read_byte(1, 0);
else if (i == len - 1){
((u8*)buff)[i] = tls_i2c_read_byte(0, 1);
break;
}
else
((u8*)buff)[i] = tls_i2c_read_byte(1, 0);
if(WM_FAILED == tls_i2c_wait_ack())
break;
}
}
return 0;
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/openLuat-luatos-soc-air101.git
git@gitlife.ru:oschina-mirror/openLuat-luatos-soc-air101.git
oschina-mirror
openLuat-luatos-soc-air101
openLuat-luatos-soc-air101
master