mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-01 21:18:48 +00:00
SM16703P test - not ready yet, just saving basic experiment progress
This commit is contained in:
@ -39,6 +39,8 @@ void BP1658CJ_Init();
|
||||
void BP1658CJ_RunFrame();
|
||||
void BP1658CJ_OnChannelChanged(int ch, int value);
|
||||
|
||||
void SM16703P_Init();
|
||||
|
||||
void BL_Shared_Init();
|
||||
void BL_ProcessUpdate(float voltage, float current, float power);
|
||||
void BL09XX_AppendInformationToHTTPIndexPage(http_request_t* request);
|
||||
|
||||
@ -78,7 +78,8 @@ static driver_t g_drivers[] = {
|
||||
{ "TESTPOWER", Test_Power_Init, Test_Power_RunFrame, BL09XX_AppendInformationToHTTPIndexPage, NULL, NULL, NULL, false },
|
||||
{ "TESTLED", Test_LED_Driver_Init, Test_LED_Driver_RunFrame, NULL, NULL, NULL, Test_LED_Driver_OnChannelChanged, false },
|
||||
|
||||
#if PLATFORM_BEKEN
|
||||
#if PLATFORM_BEKEN
|
||||
{ "SM16703P", SM16703P_Init, NULL, NULL, NULL, NULL, NULL, false },
|
||||
{ "IR", DRV_IR_Init, NULL, NULL, DRV_IR_RunFrame, NULL, NULL, false },
|
||||
{ "DDP", DRV_DDP_Init, NULL, NULL, DRV_DDP_RunFrame, DRV_DDP_Shutdown, NULL, false },
|
||||
{ "SSDP", DRV_SSDP_Init, DRV_SSDP_RunEverySecond, NULL, DRV_SSDP_RunQuickTick, DRV_SSDP_Shutdown, NULL, false },
|
||||
|
||||
192
src/driver/drv_sm16703P.c
Normal file
192
src/driver/drv_sm16703P.c
Normal file
@ -0,0 +1,192 @@
|
||||
#if PLATFORM_BEKEN
|
||||
#include "../new_common.h"
|
||||
#include "../new_pins.h"
|
||||
#include "../new_cfg.h"
|
||||
// Commands register, execution API and cmd tokenizer
|
||||
#include "../cmnds/cmd_public.h"
|
||||
#include "../mqtt/new_mqtt.h"
|
||||
#include "../logging/logging.h"
|
||||
#include "../hal/hal_pins.h"
|
||||
#include "../httpserver/new_http.h"
|
||||
|
||||
// SM16703P is 3 channels each.
|
||||
// We send 24 bits. 24 / 8 = 3. Send byte per each channel.
|
||||
|
||||
static int g_pin_di = 0;
|
||||
|
||||
/*1 equals about 5 us*/
|
||||
// From platforms/bk7231t/bk7231t_os/beken378/driver/codec/driver_codec_es8374.c
|
||||
static void es8374_codec_i2c_delayqq(int us)
|
||||
{
|
||||
volatile int i, j;
|
||||
for (i = 0; i < us; i++)
|
||||
{
|
||||
j = 50;
|
||||
while (j--);
|
||||
}
|
||||
}
|
||||
/*1 equals about 0.3 us*/
|
||||
static void es8374_codec_i2c_delay(int us)
|
||||
{
|
||||
volatile int i, j;
|
||||
for (i = 0; i < us; i++)
|
||||
{
|
||||
j = 3;
|
||||
while (j--);
|
||||
}
|
||||
}
|
||||
#define SM16703P_SLEEP_300 __asm("nop\nnop\nnop");
|
||||
#define SM16703P_SLEEP_900 __asm("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop");
|
||||
|
||||
void gpio_output(UINT32 id, UINT32 val);
|
||||
|
||||
|
||||
//#define SM16703P_SET_HIGH gpio_output(g_pin_di,true);
|
||||
//#define SM16703P_SET_LOW gpio_output(g_pin_di,false);
|
||||
|
||||
// NOTE: #define REG_WRITE(addr, _data) (*((volatile UINT32 *)(addr)) = (_data))
|
||||
#define SM16703P_SET_HIGH REG_WRITE(gpio_cfg_addr, reg_val_HIGH);
|
||||
#define SM16703P_SET_LOW REG_WRITE(gpio_cfg_addr, reg_val_LOW);
|
||||
|
||||
// gpio_output is faster
|
||||
#define SM16703P_SEND_T0 SM16703P_SET_HIGH; SM16703P_SLEEP_300; SM16703P_SET_LOW; SM16703P_SLEEP_900;
|
||||
#define SM16703P_SEND_T1 SM16703P_SET_HIGH; SM16703P_SLEEP_900; SM16703P_SET_LOW; SM16703P_SLEEP_300;
|
||||
|
||||
#ifndef CHECK_BIT
|
||||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
||||
#endif
|
||||
|
||||
#define SM16703P_SEND_BIT(var,pos) if(((var) & (1<<(pos)))) { SM16703P_SEND_T1; } else { SM16703P_SEND_T0; };
|
||||
|
||||
|
||||
#include "include.h"
|
||||
#include "arm_arch.h"
|
||||
#include "gpio_pub.h"
|
||||
#include "gpio.h"
|
||||
#include "drv_model_pub.h"
|
||||
#include "sys_ctrl_pub.h"
|
||||
#include "uart_pub.h"
|
||||
#include "intc_pub.h"
|
||||
#include "icu_pub.h"
|
||||
|
||||
static void SM16703P_Send(byte *data, int dataSize){
|
||||
int i;
|
||||
byte b;
|
||||
UINT32 reg_val;
|
||||
volatile UINT32 *gpio_cfg_addr;
|
||||
UINT32 id;
|
||||
volatile UINT32 reg_val_HIGH;
|
||||
volatile UINT32 reg_val_LOW;
|
||||
|
||||
GLOBAL_INT_DECLARATION();
|
||||
GLOBAL_INT_DISABLE();
|
||||
|
||||
id = g_pin_di;
|
||||
|
||||
#if (CFG_SOC_NAME != SOC_BK7231)
|
||||
if (id >= GPIO32)
|
||||
id += 16;
|
||||
#endif // (CFG_SOC_NAME != SOC_BK7231)
|
||||
gpio_cfg_addr = (volatile UINT32 *)(REG_GPIO_CFG_BASE_ADDR + id * 4);
|
||||
reg_val = REG_READ(gpio_cfg_addr);
|
||||
reg_val_HIGH = reg_val;
|
||||
reg_val_HIGH &= ~GCFG_OUTPUT_BIT;
|
||||
reg_val_HIGH |= (0x01 & 0x01) << GCFG_OUTPUT_POS;
|
||||
reg_val_LOW = reg_val;
|
||||
reg_val_LOW &= ~GCFG_OUTPUT_BIT;
|
||||
reg_val_LOW |= (0x00 & 0x01) << GCFG_OUTPUT_POS;
|
||||
|
||||
SM16703P_SET_LOW;
|
||||
SM16703P_SET_LOW;
|
||||
SM16703P_SET_LOW;
|
||||
SM16703P_SET_LOW;
|
||||
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
SM16703P_SEND_T0;
|
||||
//SM16703P_SLEEP_900;
|
||||
SM16703P_SEND_T0;
|
||||
|
||||
/* SM16703P_SLEEP_900;
|
||||
SM16703P_SLEEP_900;
|
||||
SM16703P_SLEEP_900;
|
||||
SM16703P_SLEEP_900;
|
||||
|
||||
for(i = 0; i < dataSize; i++) {
|
||||
b = data[i];
|
||||
SM16703P_SEND_BIT(b,0);
|
||||
SM16703P_SEND_BIT(b,1);
|
||||
SM16703P_SEND_BIT(b,2);
|
||||
SM16703P_SEND_BIT(b,3);
|
||||
SM16703P_SEND_BIT(b,4);
|
||||
SM16703P_SEND_BIT(b,5);
|
||||
SM16703P_SEND_BIT(b,6);
|
||||
SM16703P_SEND_BIT(b,7);
|
||||
}*/
|
||||
GLOBAL_INT_RESTORE();
|
||||
// For P0, it says
|
||||
// For P11, it says 0
|
||||
// For P12, it says 0
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_ENERGYMETER, "Reg val is %i", reg_val);
|
||||
}
|
||||
static int SM16703P_Test(const void *context, const char *cmd, const char *args, int flags){
|
||||
byte test[3];
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 3; i++){
|
||||
test[i] = rand();
|
||||
}
|
||||
SM16703P_Send(test,3);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// backlog startDriver SM16703P; SM16703P_Test_3xZero
|
||||
static int SM16703P_Test_3xZero(const void *context, const char *cmd, const char *args, int flags) {
|
||||
byte test[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
test[i] = 0;
|
||||
}
|
||||
SM16703P_Send(test, 3);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
// backlog startDriver SM16703P; SM16703P_Test_3xOne
|
||||
static int SM16703P_Test_3xOne(const void *context, const char *cmd, const char *args, int flags) {
|
||||
byte test[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
test[i] = 0xFF;
|
||||
}
|
||||
SM16703P_Send(test, 3);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
// startDriver SM16703P
|
||||
// backlog startDriver SM16703P; SM16703P_Test
|
||||
void SM16703P_Init() {
|
||||
|
||||
|
||||
g_pin_di = PIN_FindPinIndexForRole(IOR_SM16703P_DIN,g_pin_di);
|
||||
|
||||
HAL_PIN_Setup_Output(g_pin_di);
|
||||
|
||||
//cmddetail:{"name":"SM16703P_Test","args":"",
|
||||
//cmddetail:"descr":"qq",
|
||||
//cmddetail:"fn":"SM16703P_Test","file":"driver/drv_ucs1912.c","requires":"",
|
||||
//cmddetail:"examples":""}
|
||||
CMD_RegisterCommand("SM16703P_Test", "", SM16703P_Test, NULL, NULL);
|
||||
CMD_RegisterCommand("SM16703P_Test_3xZero", "", SM16703P_Test_3xZero, NULL, NULL);
|
||||
CMD_RegisterCommand("SM16703P_Test_3xOne", "", SM16703P_Test_3xOne, NULL, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user