11 changed files with 447 additions and 4 deletions
-
2a8000_protocol
-
9usrc/main.cpp
-
3usrc/public_service/gservice.cpp
-
5usrc/public_service/gservice.hpp
-
189usrc/subboards/subboard100_idcard_reader/eeprom_service.cpp
-
74usrc/subboards/subboard100_idcard_reader/eeprom_service.hpp
-
58usrc/subboards/subboard100_idcard_reader/pri_board.h
-
34usrc/subboards/subboard100_idcard_reader/subboard100_id_card_reader.cpp
-
26usrc/subboards/subboard100_idcard_reader/subboard100_id_card_reader.hpp
-
39usrc/subboards/subboard100_idcard_reader/subboard100_id_card_reader_board.c
-
12usrc/subboards/subboard100_idcard_reader/subboard100_id_card_reader_board.h
@ -1 +1 @@ |
|||||
Subproject commit d7a693c2c9a71a2e3b2aa3b7aefc22c8e97d4a11 |
|
||||
|
Subproject commit c6a2a14eb08bbd60018e24b866a874db6d6dff80 |
@ -0,0 +1,189 @@ |
|||||
|
#include "eeprom_service.hpp"
|
||||
|
|
||||
|
#include <stdio.h>
|
||||
|
#include <string.h>
|
||||
|
|
||||
|
using namespace std; |
||||
|
using namespace iflytop; |
||||
|
|
||||
|
#define SECTOR_SIZE (128)
|
||||
|
#define SECTOR_NUM (2 * 8) // 2k
|
||||
|
#define MAX_SIZE (SECTOR_SIZE * SECTOR_NUM)
|
||||
|
|
||||
|
#define TAG "EEPROMService"
|
||||
|
|
||||
|
/*******************************************************************************
|
||||
|
* PRIVATE * |
||||
|
*******************************************************************************/ |
||||
|
static __unused void dumpbuf(uint8_t* buf, size_t len) { |
||||
|
for (size_t i = 0; i < len;) { |
||||
|
printf("%04x: ", i); |
||||
|
for (size_t j = 0; j < 32; j++) { |
||||
|
printf("%02x ", buf[i + j]); |
||||
|
} |
||||
|
|
||||
|
printf("|"); |
||||
|
for (size_t j = 0; j < 32; j++) { |
||||
|
if (buf[i + j] >= 0x20 && buf[i + j] <= 0x7e) { |
||||
|
printf("%c", buf[i + j]); |
||||
|
} else { |
||||
|
printf("."); |
||||
|
} |
||||
|
} |
||||
|
printf("\n"); |
||||
|
i += 32; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/*******************************************************************************
|
||||
|
* CODE * |
||||
|
*******************************************************************************/ |
||||
|
|
||||
|
void EEPROMService::initialize(int id, I2C_HandleTypeDef* i2c_handle, ZIEventBusSender* event_bus_sender) { |
||||
|
m_i2c_handle = i2c_handle; |
||||
|
ZASSERT(m_i2c_handle); |
||||
|
m_mutex.init(); |
||||
|
m_monitor_thread.init(TAG, 1024, osPriorityNormal); |
||||
|
this->id = id; |
||||
|
|
||||
|
m_event_bus_sender = event_bus_sender; |
||||
|
m_subdevice_p24c16.initialize(m_i2c_handle); // 小ID卡
|
||||
|
m_subdevice_m24lrxxe.initialize(m_i2c_handle); // 大ID卡(旧)
|
||||
|
|
||||
|
// write_test_data_rom(&m_subdevice_p24c16);
|
||||
|
// write_test_data_rom(&m_subdevice_m24lrxxe);
|
||||
|
|
||||
|
start_monitor_status(); |
||||
|
} |
||||
|
|
||||
|
int32_t EEPROMService::start_monitor_status() { |
||||
|
ZLOGI(TAG, "start_monitor_status"); |
||||
|
m_monitor_thread.start([this]() { |
||||
|
// eeprom_status_t status;
|
||||
|
while (!m_monitor_thread.getExitFlag()) { |
||||
|
detect_online(); |
||||
|
osDelay(100); |
||||
|
} |
||||
|
}); |
||||
|
return 0; |
||||
|
}; |
||||
|
int32_t EEPROMService::stop_monitor_status() { |
||||
|
ZLOGI(TAG, "stop_monitor_status"); |
||||
|
m_monitor_thread.stop(); |
||||
|
return 0; |
||||
|
}; |
||||
|
|
||||
|
void EEPROMService::scan_i2c() { |
||||
|
HAL_I2C_DeInit(m_i2c_handle); |
||||
|
HAL_I2C_Init(m_i2c_handle); |
||||
|
|
||||
|
memset(i2c_ping_state, 0, sizeof(i2c_ping_state)); |
||||
|
for (uint16_t i = 0; i < 255; i++) { |
||||
|
HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(m_i2c_handle, i << 1, 1, 1); |
||||
|
if (status == HAL_OK) { |
||||
|
i2c_ping_state[i] = true; |
||||
|
} else { |
||||
|
i2c_ping_state[i] = false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void EEPROMService::dump_i2c_scan_result() { |
||||
|
ZLOGI_NOT_END_LINE(TAG, "dump_i2c_scan_result:"); |
||||
|
for (uint16_t i = 0; i < 255; i++) { |
||||
|
if (i2c_ping_state[i]) { |
||||
|
printf("%02x ", i); |
||||
|
} |
||||
|
} |
||||
|
printf("\n"); |
||||
|
} |
||||
|
|
||||
|
void EEPROMService::detect_online() { |
||||
|
zlock_guard guard(m_mutex); |
||||
|
if (!m_nowonline) { |
||||
|
scan_i2c(); |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* 这里只是简单的判断eeprom的类型,并不是通用的判断逻辑, 仅仅是为了巴迪泰A8000设备而设计 |
||||
|
* 巴迪泰项目中,eeprom只有两种,p24c16和m24lrxxe,且容积都是2kbyte |
||||
|
* 这里的判断逻辑: |
||||
|
* p24c16 :地址包换 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57 |
||||
|
* m24lrxxe:地址只包换 0x53,0x57 |
||||
|
* |
||||
|
* @param i2c_ping_state |
||||
|
*/ |
||||
|
|
||||
|
if (i2c_ping_state[0x50] && i2c_ping_state[0x51] && i2c_ping_state[0x52]) { |
||||
|
m_nowonline = &m_subdevice_p24c16; |
||||
|
change_is_online_flag(true); |
||||
|
ZLOGI(TAG, "detect eerpom p24c16"); |
||||
|
} else if (!i2c_ping_state[0x50] && i2c_ping_state[0x53] && i2c_ping_state[0x57]) { |
||||
|
m_nowonline = &m_subdevice_m24lrxxe; |
||||
|
change_is_online_flag(true); |
||||
|
ZLOGI(TAG, "detect eerpom m24lrxxe"); |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
if (!m_nowonline->isOnline()) { |
||||
|
m_nowonline = nullptr; |
||||
|
change_is_online_flag(false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int32_t EEPROMService::module_read_raw(int32_t index, uint8_t* data, int32_t* len) { |
||||
|
zlock_guard guard(m_mutex); |
||||
|
if (!m_nowonline) return err::kdevice_offline; |
||||
|
if (*len < SECTOR_SIZE) return err::kbuffer_not_enough; |
||||
|
|
||||
|
uint16_t add = index * SECTOR_SIZE; |
||||
|
*len = SECTOR_SIZE; |
||||
|
|
||||
|
ZLOGI(TAG, "read: %d, %d", add, *len); |
||||
|
int32_t val = m_nowonline->read(add, data, len); |
||||
|
// dumpbuf(data, *len);
|
||||
|
return val; |
||||
|
} |
||||
|
|
||||
|
int32_t EEPROMService::module_xxx_reg(int32_t param_id, bool read, int32_t& val) { |
||||
|
switch (param_id) { |
||||
|
PROCESS_REG(kreg_id_card_reader_raw_sector_size, /* */ REG_GET(SECTOR_SIZE), ACTION_NONE); |
||||
|
PROCESS_REG(kreg_id_card_reader_raw_sector_num, /* */ REG_GET(SECTOR_NUM), ACTION_NONE); |
||||
|
PROCESS_REG(kreg_id_card_reader_is_online, /* */ REG_GET(m_is_online_flag), ACTION_NONE); |
||||
|
default: |
||||
|
return err::kmodule_not_find_reg; |
||||
|
break; |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
void EEPROMService::change_is_online_flag(bool state) { |
||||
|
if (m_is_online_flag != state) { |
||||
|
ZLOGI(TAG, "change_is_online_flag: %d", state); |
||||
|
m_is_online_flag = state; |
||||
|
if (m_event_bus_sender) { |
||||
|
m_event_bus_sender->push_reg_state_change_event(id, kreg_id_card_reader_is_online, !m_is_online_flag, m_is_online_flag); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
int32_t EEPROMService::module_get_status(int32_t* status) { |
||||
|
if (!m_monitor_thread.isworking()) { |
||||
|
return 0; |
||||
|
} |
||||
|
return 1; |
||||
|
} |
||||
|
void EEPROMService::write_test_data_rom(ZI_EEPROM* rom) { |
||||
|
uint32_t data = 0; |
||||
|
uint32_t readdata = 0; |
||||
|
for (uint16_t i = 0; i < 2 * 1024;) { |
||||
|
int32_t wlen = 4; |
||||
|
rom->write(i, (uint8_t*)&data, &wlen); |
||||
|
rom->read(i, (uint8_t*)&readdata, &wlen); |
||||
|
|
||||
|
ZLOGI(TAG, "off:%x w:%d,r:%d", i, data, readdata); |
||||
|
data += 1; |
||||
|
i += 4; |
||||
|
} |
||||
|
} |
@ -0,0 +1,74 @@ |
|||||
|
|
||||
|
|
||||
|
#include "sdk\components\sensors\i2ceeprom\m24lrxxe_i2c_eeprom.hpp"
|
||||
|
#include "sdk\components\sensors\i2ceeprom\p24c16_eeprom.hpp"
|
||||
|
//
|
||||
|
#include "sdk\os\zos.hpp"
|
||||
|
|
||||
|
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
|
namespace iflytop { |
||||
|
using namespace std; |
||||
|
// ref:https://iflytop1.feishu.cn/wiki/PO1LwwvaNi4F10kiobMcjSK4nBg
|
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* @Warning |
||||
|
* 此服务专门为巴迪泰A8000设备完成,代码其中存在一些默认条件 |
||||
|
* 1. eeprom只有两种,p24c16和m24lrxxe |
||||
|
* 2. eeprom的容积为2kbyte |
||||
|
*/ |
||||
|
|
||||
|
class EEPROMService : public ZIModule { |
||||
|
ENABLE_MODULE(EEPROMService,ka8000_idcard_reader,PC_VERSION) |
||||
|
I2C_HandleTypeDef* m_i2c_handle; |
||||
|
ZThread m_monitor_thread; |
||||
|
bool m_is_online_flag = false; |
||||
|
zmutex m_mutex; |
||||
|
ZIEventBusSender* m_event_bus_sender; |
||||
|
|
||||
|
int32_t id = 0; |
||||
|
|
||||
|
bool i2c_ping_state[255] = {0}; |
||||
|
ZI_EEPROM* m_nowonline = nullptr; |
||||
|
|
||||
|
public: |
||||
|
/*******************************************************************************
|
||||
|
* SUBDEVICE * |
||||
|
*******************************************************************************/ |
||||
|
P24C16 m_subdevice_p24c16; |
||||
|
M24LRXXE_I2C_EEPROM m_subdevice_m24lrxxe; |
||||
|
|
||||
|
public: |
||||
|
EEPROMService(){}; |
||||
|
~EEPROMService(){}; |
||||
|
|
||||
|
void initialize(int id, I2C_HandleTypeDef* i2c_handle, ZIEventBusSender* event_bus_sender); |
||||
|
|
||||
|
public: |
||||
|
int32_t start_monitor_status(); |
||||
|
int32_t stop_monitor_status(); |
||||
|
|
||||
|
private: |
||||
|
void scan_i2c(); |
||||
|
void dump_i2c_scan_result(); |
||||
|
void detect_online(); |
||||
|
|
||||
|
public: |
||||
|
virtual int32_t getid(int32_t* id) override { |
||||
|
*id = this->id; |
||||
|
return 0; |
||||
|
} |
||||
|
virtual int32_t module_read_raw(int32_t index, uint8_t* data, int32_t* len); |
||||
|
|
||||
|
private: |
||||
|
virtual int32_t module_get_status(int32_t* status) override; |
||||
|
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& param_value) override; |
||||
|
|
||||
|
private: |
||||
|
void change_is_online_flag(bool state); |
||||
|
void write_test_data_rom(ZI_EEPROM* rom); |
||||
|
}; |
||||
|
} // namespace iflytop
|
||||
|
|
||||
|
#endif
|
@ -0,0 +1,58 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
/*********************************************************************************************************************** |
||||
|
* 板载扩展IO * |
||||
|
***********************************************************************************************************************/ |
||||
|
#define EXT_INPUT_IO0 PD4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO1 PD5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO2 PD6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO3 PD7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO4 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO5 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO6 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO7 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO8 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
#define EXT_INPUT_IO9 PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true |
||||
|
|
||||
|
#define EXT_OUTPUT_IO0 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO1 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO2 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO3 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO4 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO5 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO6 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO7 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO8 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
#define EXT_OUTPUT_IO9 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ |
||||
|
|
||||
|
#define TMC_MOTOR_SPI hspi1 |
||||
|
|
||||
|
/*********************************************************************************************************************** |
||||
|
* 左右移动 * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
// MOTOR1 |
||||
|
#define TMC_MOTOR1_CHANNEL 1 |
||||
|
#define TMC_MOTOR1_SPI_SELECT1_IO PA4 |
||||
|
#define TMC_MOTOR1_nFREEZE_IO PC2 |
||||
|
#define TMC_MOTOR1_nRESET_IO PB3 |
||||
|
#define TMC_MOTOR1_SUB_IC_ENN_IO PC3 |
||||
|
#define TMC_MOTOR1_ENN_IO // unused |
||||
|
|
||||
|
// MOTOR2 |
||||
|
#define TMC_MOTOR2_CHANNEL 2 |
||||
|
#define TMC_MOTOR2_SPI_SELECT1_IO PA8 |
||||
|
#define TMC_MOTOR2_nFREEZE_IO PC6 |
||||
|
#define TMC_MOTOR2_nRESET_IO PB2 |
||||
|
#define TMC_MOTOR2_SUB_IC_ENN_IO PC7 |
||||
|
#define TMC_MOTOR2_ENN_IO // unused |
||||
|
|
||||
|
#define ARM_X_ZERO PD0 |
||||
|
#define ARM_X_LIMIT PD1 |
||||
|
#define ARM_Y_ZERO PD2 |
||||
|
#define ARM_Y_LIMIT PD3 |
||||
|
|
||||
|
#define ARM_SENSOR5_GPIO PD4 |
||||
|
#define ARM_SENSOR6_GPIO PD5 |
||||
|
#define ARM_SENSOR7_GPIO PD6 |
||||
|
#define ARM_SENSOR8_GPIO PD7 |
@ -0,0 +1,34 @@ |
|||||
|
#include "subboard100_id_card_reader.hpp"
|
||||
|
extern "C" { |
||||
|
#include "subboard100_id_card_reader_board.h"
|
||||
|
} |
||||
|
#include "eeprom_service.hpp"
|
||||
|
#include "pri_board.h"
|
||||
|
#include "public_service/instance_init.hpp"
|
||||
|
#include "public_service/public_service.hpp"
|
||||
|
#include "sdk/components/mini_servo_motor/feite_servo_motor.hpp"
|
||||
|
#include "sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp"
|
||||
|
#include "sdk/components/sensors/m3078/m3078_code_scaner.hpp"
|
||||
|
#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
|
||||
|
#include "sdk/components/tmc/ic/ztmc4361A.hpp"
|
||||
|
#include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
|
||||
|
#include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
|
||||
|
|
||||
|
#define TAG "Subboard100IdCardReader"
|
||||
|
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
/***********************************************************************************************************************
|
||||
|
* IMPL * |
||||
|
***********************************************************************************************************************/ |
||||
|
void Subboard100IdCardReader::initialize() { |
||||
|
IO_INIT(); |
||||
|
GService::inst()->getZCanProtocolParser()->registerModule(this); |
||||
|
#if 1
|
||||
|
static EEPROMService eepromService; |
||||
|
|
||||
|
eepromService.initialize(getmoduleId(1), &hi2c1, ProtocolEventBusSender::inst()); |
||||
|
GService::inst()->registerModule(&eepromService); |
||||
|
|
||||
|
#endif
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
#include <stddef.h>
|
||||
|
#include <stdio.h>
|
||||
|
|
||||
|
//
|
||||
|
#include "configs/device_id_mgr.hpp"
|
||||
|
#include "sdk/chip/chip.hpp"
|
||||
|
#include "sdk/os/zos.hpp"
|
||||
|
//
|
||||
|
#include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp"
|
||||
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
||||
|
#include "public_service/public_service.hpp"
|
||||
|
|
||||
|
namespace iflytop { |
||||
|
class Subboard100IdCardReader : public ExtBoardImpl { |
||||
|
public: |
||||
|
static Subboard100IdCardReader *ins() { |
||||
|
static Subboard100IdCardReader instance; |
||||
|
return &instance; |
||||
|
} |
||||
|
|
||||
|
void initialize(); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
||||
|
|
||||
|
|
@ -0,0 +1,39 @@ |
|||||
|
#include "main.h" |
||||
|
#include "public_service/public_service.h" |
||||
|
|
||||
|
void MX_I2C1_Init(void) { |
||||
|
__HAL_RCC_GPIOB_CLK_ENABLE(); |
||||
|
__HAL_RCC_I2C1_CLK_ENABLE(); |
||||
|
|
||||
|
hi2c1.Instance = I2C1; |
||||
|
hi2c1.Init.ClockSpeed = 50000; |
||||
|
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; |
||||
|
hi2c1.Init.OwnAddress1 = 0; |
||||
|
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
||||
|
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
||||
|
hi2c1.Init.OwnAddress2 = 0; |
||||
|
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
||||
|
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
||||
|
if (HAL_I2C_Init(&hi2c1) != HAL_OK) { |
||||
|
Error_Handler(); |
||||
|
} |
||||
|
|
||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||||
|
|
||||
|
/**I2C1 GPIO Configuration |
||||
|
PB6 ------> I2C1_SCL |
||||
|
PB7 ------> I2C1_SDA |
||||
|
*/ |
||||
|
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7; |
||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||
|
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; |
||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||||
|
hi2c1_enable = true; |
||||
|
} |
||||
|
|
||||
|
void subboard100_id_card_reader_board_init() { |
||||
|
common_hardware_init(); |
||||
|
MX_I2C1_Init(); |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#pragma once |
||||
|
#include "main.h" |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
void subboard100_id_card_reader_board_init(); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue