Compare commits

...

2 Commits

@ -0,0 +1,79 @@
#include "app_gpio.h"
void Gpio_Port_Initialization(void)
{
SYS_ClockEnable(SYS_PERIPH_CLOCK_GPIO0);
}
void GPIO0_IRQHandler(void)
{
GPIO_Handler(0);
}
void Gpio_Set_Port_Output(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown)
{
gpio_cfg_t gpio_out;
gpio_out.port = Port;
gpio_out.mask = Pin;
gpio_out.pad = PullUpDown;
gpio_out.func = GPIO_FUNC_OUT;
GPIO_Config(&gpio_out);
}
void Gpio_Set_Port_Input(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown)
{
gpio_cfg_t gpio_in;
gpio_in.port = Port;
gpio_in.mask = Pin;
gpio_in.pad = PullUpDown;
gpio_in.func = GPIO_FUNC_IN;
GPIO_Config(&gpio_in);
}
void Gpio_Register_Interrupt_Callback(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown, gpio_int_pol_t int_state, gpio_callback_fn callback, void* pCallbackParam)
{
gpio_cfg_t gpio_interrupt;
gpio_interrupt.port = Port;
gpio_interrupt.mask = Pin;
gpio_interrupt.pad = PullUpDown;
gpio_interrupt.func = GPIO_FUNC_IN;
GPIO_Config(&gpio_interrupt);
GPIO_RegisterCallback(&gpio_interrupt, callback, pCallbackParam);
GPIO_IntConfig(&gpio_interrupt, GPIO_INT_EDGE, int_state);
GPIO_IntEnable(&gpio_interrupt);
NVIC_EnableIRQ((IRQn_Type)MXC_GPIO_GET_IRQ(Port));
}
void Gpio_UnRegister_Interrupt_Callback(uint32_t port, uint32_t pin)
{
gpio_cfg_t gpio_interrupt;
gpio_interrupt.port = port;
gpio_interrupt.mask = pin;
GPIO_RegisterCallback(&gpio_interrupt, NULL, NULL);
}
uint32_t Gpio_Get_InputState(uint32_t Port, uint32_t Pin)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(Port);
return (gpio->in & Pin);
}
void Gpio_Output_Set(uint32_t port, uint32_t pin)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(port);
gpio->out_set = pin;
}
void Gpio_Output_Clear(uint32_t port, uint32_t pin)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(port);
gpio->out_clr = pin;
}
void Gpio_Output_Toggle(uint32_t port, uint32_t pin)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(port);
gpio->out ^= pin;
}

@ -0,0 +1,20 @@
/** \file app_gpio.h */
#if !defined(APP_GPIO_H__A8A8D350_41F8_4088_82AF_828DD09BCABF__INCLUDED_)
#define APP_GPIO_H__A8A8D350_41F8_4088_82AF_828DD09BCABF__INCLUDED_
#include "board_config.h"
void Gpio_Port_Initialization(void);
void Gpio_Set_Port_Output(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown);
void Gpio_Set_Port_Input(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown);
void Gpio_Register_Interrupt_Callback(uint32_t Port, uint32_t Pin, gpio_pad_t PullUpDown, gpio_int_pol_t int_state, gpio_callback_fn callback, void* pCallbackParam);
void Gpio_UnRegister_Interrupt_Callback(uint32_t port, uint32_t pin);
uint32_t Gpio_Get_InputState(uint32_t Port, uint32_t Pin);
void Gpio_Output_Set(uint32_t port, uint32_t pin);
void Gpio_Output_Clear(uint32_t port, uint32_t pin);
void Gpio_Output_Toggle(uint32_t port, uint32_t pin);
#endif

@ -82,7 +82,7 @@ bool App_Gpio_I2C_WriteData(uint8_t TxData)
APP_GPIO_I2C_SDA_INPUT;
APP_GPIO_I2C_SCL_H;
App_Gpio_I2C_Delay();
bRet = APP_GPIO_I2C_READ;
bRet = !APP_GPIO_I2C_READ;
App_Gpio_I2C_Delay();
APP_GPIO_I2C_SCL_L;
@ -239,7 +239,7 @@ static void App_Gpio_I2C_Port_L(uint32_t Port, uint32_t Pin)
static bool App_Gpio_I2C_Port_Read(uint32_t Port, uint32_t Pin)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(Port);
return (gpio->in & Pin) ? false : true;
return (gpio->in & Pin) ? true : false;
}

@ -0,0 +1,269 @@
#include "app_oled.h"
#include "app_gpio.h"
#include "app_log.h"
#include "sw_timer.h"
#include "ssd1306.h"
#define OLED_POWER_PORT PORT_0
#define OLED_POWER_PIN PIN_4
#define OLED_POWER_ON Gpio_Output_Set(OLED_POWER_PORT, OLED_POWER_PIN);
#define OLED_POWER_OFF Gpio_Output_Clear(OLED_POWER_PORT, OLED_POWER_PIN);
#define OLED_POWER_T Gpio_Output_Toggle(OLED_POWER_PORT, OLED_POWER_PIN);
#define OLED_POWER_ON_OFF_WAIT_TIME 100
#define OLED_ERROR_PRINT_INTERVAL 1000
#define OLED_SHOW_LOG_WAIT_TIME 1000
#define OLED_SHOW_LOG_INVERSE_WAIT_TIME 1000
#define OLED_UPDATE_TEMP_INTERVAL 100
static OLED_STEP oled_step;
static OLED_STEP oled_pre_step;
static uint32_t oled_tickCount;
uint32_t oled_shift_index;
uint16_t oled_draw_temp;
static void Oled_Process(void);
static void Oled_Next_Step(OLED_STEP nextStep);
bool Oled_Initialization(void)
{
oled_step = OLED_STEP_INIT;
oled_pre_step = OLED_STEP_INIT;
//Gpio_Set_Port_Output(OLED_POWER_PORT, OLED_POWER_PIN, GPIO_PAD_PULL_UP);
//OLED_POWER_OFF;
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1, Oled_Process);
}
void Oled_Test(void)
{
OLED_POWER_T;
}
static void Oled_Process(void)
{
switch(oled_step)
{
case OLED_STEP_INIT:
Gpio_Set_Port_Output(OLED_POWER_PORT, OLED_POWER_PIN, GPIO_PAD_PULL_UP);
OLED_POWER_OFF;
oled_tickCount = millis();
Oled_Next_Step(OLED_STEP_POWER_OFF_WAIT);
break;
case OLED_STEP_POWER_OFF_WAIT:
if((millis() - oled_tickCount) >= OLED_POWER_ON_OFF_WAIT_TIME)
{
Oled_Next_Step(OLED_STEP_POWER_ON);
}
break;
case OLED_STEP_POWER_ON:
OLED_POWER_ON;
oled_tickCount = millis();
Oled_Next_Step(OLED_STEP_POWER_ON_WAIT);
break;
case OLED_STEP_POWER_ON_WAIT:
if((millis() - oled_tickCount) >= OLED_POWER_ON_OFF_WAIT_TIME)
{
Oled_Next_Step(OLED_STEP_SET_INIT);
}
break;
case OLED_STEP_SET_INIT:
if(SSD1306_Init(SSD1306_ADDR) != SSD1306_SUCCESS)
{
Oled_Next_Step(OLED_STEP_ERROR);
}
else
{
Oled_Next_Step(OLED_STEP_NORMAL_SCREEN_SET);
}
break;
case OLED_STEP_NORMAL_SCREEN_SET:
SSD1306_NormalScreen (SSD1306_ADDR);
SSD1306_ClearScreen ();
Oled_Next_Step(OLED_STEP_DRAW_LOG);
break;
case OLED_STEP_DRAW_LOG:
SSD1306_DrawBackGround_Log();
SSD1306_UpdateScreen (SSD1306_ADDR);
oled_tickCount = millis();
Oled_Next_Step(OLED_STEP_WAIT_LOG);
break;
case OLED_STEP_WAIT_LOG:
if((millis() - oled_tickCount) >= OLED_SHOW_LOG_WAIT_TIME)
{
Oled_Next_Step(OLED_STEP_LOG_INVERSE);
}
break;
case OLED_STEP_LOG_INVERSE:
SSD1306_InverseScreen (SSD1306_ADDR);
oled_tickCount = millis();
Oled_Next_Step(OLED_STEP_WAIT_LOG_INVERSE);
break;
case OLED_STEP_WAIT_LOG_INVERSE:
if((millis() - oled_tickCount) >= OLED_SHOW_LOG_INVERSE_WAIT_TIME)
{
Oled_Next_Step(OLED_STEP_LOG_NORMAL);
}
break;
case OLED_STEP_LOG_NORMAL:
SSD1306_NormalScreen (SSD1306_ADDR);
oled_shift_index = 0;
Oled_Next_Step(OLED_STEP_LOG_LEFT_SCROL);
break;
case OLED_STEP_LOG_LEFT_SCROL:
SSD1306_DrawBackGround_LeftShift(1);
if(oled_shift_index % 2 == 0)
{
SSD1306_UpdateScreen (SSD1306_ADDR);
}
oled_shift_index++;
if(oled_shift_index >= 128)
{
Oled_Next_Step(OLED_STEP_DRAW_BACKGROUND);
}
break;
case OLED_STEP_DRAW_BACKGROUND:
SSD1306_DrawBackGround();
SSD1306_Draw_Temperature(oled_draw_temp);
SSD1306_UpdateScreen (SSD1306_ADDR);
oled_tickCount = millis();
Oled_Next_Step(OLED_STEP_DRAW_TEMP);
break;
case OLED_STEP_DRAW_TEMP:
if((millis() - oled_tickCount) >= OLED_UPDATE_TEMP_INTERVAL)
{
oled_tickCount = millis();
SSD1306_Draw_Temperature(oled_draw_temp);
SSD1306_UpdateScreen (SSD1306_ADDR);
}
break;
case OLED_STEP_ERROR:
if((millis() - oled_tickCount) >= OLED_ERROR_PRINT_INTERVAL)
{
oled_tickCount = millis();
dbg_printf(LOG_LEVEL_DEBUG, "Oled Step Error %d\r\n", oled_pre_step);
}
break;
}
}
static void Oled_Next_Step(OLED_STEP nextStep)
{
oled_pre_step = oled_step;
oled_step = nextStep;
}
#if 0
if(SSD1306_Init(SSD1306_ADDR) != SSD1306_SUCCESS)
{
printf("ssd1306 init fail\r\n");
}
else
{
uint8_t i;
SSD1306_NormalScreen (SSD1306_ADDR);
SSD1306_ClearScreen ();
SSD1306_DrawBackGround_Log();
SSD1306_UpdateScreen (SSD1306_ADDR);
Delay_ms(1500);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms(1500);
SSD1306_NormalScreen (SSD1306_ADDR);
for(i = 0 ; i < 128 ; i++)
{
SSD1306_DrawBackGround_LeftShift(1);
if(i % 2 == 0)
{
SSD1306_UpdateScreen (SSD1306_ADDR);
}
//Delay_ms(10);
}
SSD1306_DrawBackGround();
SSD1306_UpdateScreen (SSD1306_ADDR);
#if 0
SSD1306_NormalScreen (SSD1306_ADDR);
SSD1306_ClearScreen (); // clear screen
SSD1306_DrawLine (0, MAX_X, 4, 4); // draw line
SSD1306_SetPosition (7, 1); // set position
SSD1306_DrawString ("SSD1306 OLED DRIVER"); // draw string
SSD1306_DrawLine (0, MAX_X, 18, 18); // draw line
SSD1306_SetPosition (40, 3); // set position
SSD1306_DrawString ("MATIASUS"); // draw string
//SSD1306_SetPosition (53, 5); // set position
//SSD1306_DrawString ("2021"); // draw string
SSD1306_UpdateScreen (SSD1306_ADDR); // update
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
#if 0
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
#endif
#endif
}
#endif

@ -0,0 +1,39 @@
/** \file app_oled.h */
#if !defined(APP_OLED_H__6B909B42_366E_4E67_91F9_577B515933F7__INCLUDED_)
#define APP_OLED_H__6B909B42_366E_4E67_91F9_577B515933F7__INCLUDED_
#include "board_config.h"
typedef enum
{
OLED_STEP_INIT,
OLED_STEP_POWER_OFF_WAIT,
OLED_STEP_POWER_ON,
OLED_STEP_POWER_ON_WAIT,
OLED_STEP_SET_INIT,
OLED_STEP_NORMAL_SCREEN_SET,
OLED_STEP_DRAW_LOG,
OLED_STEP_WAIT_LOG,
OLED_STEP_LOG_INVERSE,
OLED_STEP_WAIT_LOG_INVERSE,
OLED_STEP_LOG_NORMAL,
OLED_STEP_LOG_LEFT_SCROL,
OLED_STEP_DRAW_BACKGROUND,
OLED_STEP_DRAW_TEMP,
OLED_STEP_ERROR,
}OLED_STEP;
bool Oled_Initialization(void);
#endif

@ -116,7 +116,7 @@ static void App_Uart_Read_Callback(uart_req_t* req, int error)
static void App_Uart_Data_Transmit_Check(void)
{
if(RingBuffer_Get_DataSize(&Tx_RingBuffer) != 0 && UART_Busy(APP_UART_INSTANCE) == E_NO_ERROR)
if(RingBuffer_Get_DataSize(&Tx_RingBuffer) != 0 && UART_Busy(APP_UART_INSTANCE) != E_BUSY)
{
uint8_t TxData;
RingBuffer_GetData(&Tx_RingBuffer, &TxData);

@ -3,6 +3,7 @@
#include "struct.h"
#include "sw_timer.h"
#include "app_gpio.h"
#include "app_gpio_led.h"
#include "app_gpio_i2c.h"
#include "app_i2c_master.h"
@ -13,6 +14,9 @@
#include "app_log.h"
#include "app_cli.h"
#include "app_oled.h"
void Test_Process(void)
@ -40,95 +44,21 @@ int main(void)
SystemCoreClockSet(HIRC_96MHZ);
App_Uart_Initialization();
App_Gpio_I2C_Initialization(100000);
Gpio_Port_Initialization();
App_Gpio_I2C_Initialization(200000);
I2C_Master_Initialization(TEMP_I2C_INSTANCE, I2C_FAST_MODE);
App_Led_Initialization();
App_CLI_Initialization();
Oled_Initialization();
__enable_irq();
App_Led_OutputSet(APP_LED_1, APP_LED_MODE_TOGGLE, 100, 900);
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1000,Test_Process );
#if 0
if(SSD1306_Init(SSD1306_ADDR) != SSD1306_SUCCESS)
{
printf("ssd1306 init fail\r\n");
}
else
{
uint8_t i;
SSD1306_NormalScreen (SSD1306_ADDR);
SSD1306_ClearScreen ();
SSD1306_DrawBackGround_Log();
SSD1306_UpdateScreen (SSD1306_ADDR);
Delay_ms(1500);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms(1500);
SSD1306_NormalScreen (SSD1306_ADDR);
for(i = 0 ; i < 128 ; i++)
{
SSD1306_DrawBackGround_LeftShift(1);
if(i % 2 == 0)
{
SSD1306_UpdateScreen (SSD1306_ADDR);
}
//Delay_ms(10);
}
SSD1306_DrawBackGround();
SSD1306_UpdateScreen (SSD1306_ADDR);
#if 0
SSD1306_NormalScreen (SSD1306_ADDR);
SSD1306_ClearScreen (); // clear screen
SSD1306_DrawLine (0, MAX_X, 4, 4); // draw line
SSD1306_SetPosition (7, 1); // set position
SSD1306_DrawString ("SSD1306 OLED DRIVER"); // draw string
SSD1306_DrawLine (0, MAX_X, 18, 18); // draw line
SSD1306_SetPosition (40, 3); // set position
SSD1306_DrawString ("MATIASUS"); // draw string
//SSD1306_SetPosition (53, 5); // set position
//SSD1306_DrawString ("2021"); // draw string
SSD1306_UpdateScreen (SSD1306_ADDR); // update
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
#if 0
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_InverseScreen (SSD1306_ADDR);
Delay_ms (1000);
SSD1306_NormalScreen (SSD1306_ADDR);
#endif
#endif
}
#endif
COMPLETE:

@ -7,7 +7,7 @@
#define AK9757W_ERROR_PRINT_INTERVAL 1000
@ -17,15 +17,25 @@ static AK9757W_HANDLER AK9757W_Handler;
static AK9757W_HANDLER* pHandler = &AK9757W_Handler;
const uint8_t default_cntl_reg_data[] = {0x20, 0xFF, 0xFE, 0x4A, 0xE1, 0x00, 0x00, 0x00, 0xDF, 0xE0};
const uint8_t default_fcoef_reg_data[] = {0x29, 0xF3, 0x57, 0x30, 0x6B, 0xBE, 0x21, 0x61, 0x8D, 0x10, 0x8D, 0xBF, 0x01, 0x0C, 0xFE};
const uint8_t default_gcoef_reg_data[] = {0x37, 0x7D, 0x48, 0x40, 0xF1, 0xB7, 0x33, 0x83, 0x5C, 0x20, 0x40, 0xAB, 0x12, 0x70, 0x40};
const uint8_t default_xcoef_reg_data[] = {0x45, 0xC7, 0xA0, 0x32, 0x78, 0x42, 0x23, 0x75, 0x92, 0x16, 0xC5, 0x42, 0x08, 0x15, 0x60};
const uint8_t default_gir_oir_gts_ots_git_reg_data[] = {0x53, 0xE0, 0x94, 0x12, 0x00, 0x00, 0x0D, 0x14, 0x00, 0x00};
static bool AK9757W_Check_CompanyCode(void);
static bool AK9757W_Set_Operation_Mode(AK9757W_MODE mode);
static bool AK9757W_Set_ADC_Inverter(AK9757W_MODE mode);
static bool AK9757W_Set_CNTL1_9_Parameter(void);
static bool AK9757W_Set_FCOEF4_0_Parameter(void);
static bool AK9757W_Set_GCOEF4_0_Parameter(void);
static bool AK9757W_Set_XCOEF4_0_Parameter(void);
static bool AK9757W_Set_IR_TS_IT_Parameter(void);
static bool AK9757W_Process(void);
static void AK9757W_Next_Step(AK9757W_STEP nextStep);
@ -36,8 +46,10 @@ static bool AK9757W_Process(void);
bool AK9757W_Initialization(void)
{
AK9757W_Handler.PreStep = STEP_INIT;
AK9757W_Handler.Step = STEP_INIT;
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 10, AK9757W_Process);
SW_Timer_Callback_Register(SW_TIMER_RUN_CONTINUE, 1, AK9757W_Process);
return true;
@ -76,53 +88,93 @@ static bool AK9757W_Process(void)
case STEP_INIT:
AK9757W_Handler.isInitComplete = false;
AK9757W_Handler.SensorID = 0xFFFFFFFF;
pHandler->Step = STEP_CHECK_COMPANY;
AK9757W_Next_Step(STEP_CHECK_COMPANY);
break;
case STEP_CHECK_COMPANY:
if(AK9757W_Check_CompanyCode() == false){
pHandler->Step = STEP_ERROR;
AK9757W_Next_Step(STEP_ERROR);
}else{
pHandler->Step = STEP_CHECK_ID_POWER_ON;
AK9757W_Next_Step(STEP_CHECK_ID_POWER_ON);
}
break;
case STEP_CHECK_ID_POWER_ON:
if(AK9757_Set_Mode(AK9757W_MODE_CONTINUOUS_MODE) == false){
pHandler->Step = STEP_ERROR;
if(AK9757W_Set_Mode(AK9757W_MODE_CONTINUOUS_MODE) == false){
AK9757W_Next_Step(STEP_ERROR);
}else{
pHandler->TickCount = millis();
AK9757W_Handler.Step = STEP_CHECK_ID_POWER_ON_WAIT;
AK9757W_Next_Step(STEP_CHECK_ID_POWER_ON_WAIT);
}
break;
case STEP_CHECK_ID_POWER_ON_WAIT:
if((millis() - pHandler->TickCount) >= AK9757W_CHIPID_READ_WAIT_TIME)
pHandler->Step = STEP_CHECK_ID_READ;
AK9757W_Next_Step(STEP_CHECK_ID_READ);
break;
case STEP_CHECK_ID_READ:
if(AK9757_Get_SensorID() == false){
pHandler->Step = STEP_ERROR;
if(AK9757W_Get_SensorID() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
pHandler->Step = STEP_CHECK_ID_POWER_OFF;
AK9757W_Next_Step(STEP_CHECK_ID_POWER_OFF);
}
break;
case STEP_CHECK_ID_POWER_OFF:
if(AK9757_Set_Mode(AK9757W_MODE_STAND_BY_MODE) == false){
pHandler->Step = STEP_ERROR;
if(AK9757W_Set_Mode(AK9757W_MODE_STAND_BY_MODE) == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Handler.Step = STEP_WRITE_CNTL1_9;
AK9757W_Next_Step(STEP_WRITE_CNTL1_9);
}
break;
case STEP_WRITE_CNTL1_9:
if(AK9757_Set_CTL1_9_Parameter() == false){
if(AK9757W_Set_CNTL1_9_Parameter() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Next_Step(STEP_WRITE_FCOEF4_0);
}
break;
case STEP_WRITE_FCOEF4_0:
if(AK9757W_Set_FCOEF4_0_Parameter() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Next_Step(STEP_WRITE_GCOEF4_0);
}
break;
case STEP_WRITE_GCOEF4_0:
if(AK9757W_Set_GCOEF4_0_Parameter() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Next_Step(STEP_WRITE_XCOEF4_0);
}
break;
case STEP_WRITE_XCOEF4_0:
if(AK9757W_Set_XCOEF4_0_Parameter() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Next_Step(STEP_WRITE_IR_TS_IT);
}
break;
case STEP_WRITE_IR_TS_IT:
if(AK9757W_Set_IR_TS_IT_Parameter() == false){
AK9757W_Next_Step(STEP_ERROR);
}
else{
AK9757W_Next_Step(STEP_ERROR);
}
break;
case STEP_ERROR:
if((millis() - pHandler->TickCount) >= AK9757W_ERROR_PRINT_INTERVAL)
{
pHandler->TickCount = millis();
dbg_printf(LOG_LEVEL_DEBUG, "ak975f7w Step Error %d\r\n", pHandler->PreStep);
}
break;
}
@ -176,7 +228,7 @@ static bool AK9757W_Check_CompanyCode(void)
}
bool AK9757_Set_Mode(AK9757W_MODE mode)
bool AK9757W_Set_Mode(AK9757W_MODE mode)
{
int error;
uint8_t TxBuff[10];
@ -205,23 +257,92 @@ bool AK9757_Set_Mode(AK9757W_MODE mode)
return true;
}
bool AK9757_Set_AD_OutputDataTyte(AK9757W_IR_ADC_INVERT type)
bool AK9757W_Set_AD_OutputDataTyte(AK9757W_IR_ADC_INVERT type)
{
}
static bool AK9757W_Set_CNTL1_9_Parameter(void)
{
int error;
uint8_t i;
memcpy(&pHandler->Cntl_Info.CNTL_Buff[0], &default_cntl_reg_data[1], (sizeof(default_cntl_reg_data)-1));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &default_cntl_reg_data[0], sizeof(default_cntl_reg_data));
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C CTL1_9 write Error %d\r\n", error);
return false;
}
return true;
}
static bool AK9757W_Set_FCOEF4_0_Parameter(void)
{
int error;
uint8_t i;
uint8_t RxBuff[20];
memcpy(&pHandler->Fcoef_Info.FCOEF_Buff[0], &default_fcoef_reg_data[1], (sizeof(default_fcoef_reg_data)-1));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &default_fcoef_reg_data[0], sizeof(default_fcoef_reg_data));
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C FCOEF4_0 write Error %d\r\n", error);
return false;
}
dbg_printf(LOG_LEVEL_DEBUG, "I2C FCOEF4_0 write Success\r\n");
return true;
}
static bool AK9757W_Set_GCOEF4_0_Parameter(void)
{
int error;
uint8_t i;
memcpy(&pHandler->Gcoef_Info.GCOEF_Buff[0], &default_gcoef_reg_data[1], (sizeof(default_gcoef_reg_data)-1));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &default_gcoef_reg_data[0], sizeof(default_gcoef_reg_data));
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C GCOEF4_0 write Error %d\r\n", error);
return false;
}
dbg_printf(LOG_LEVEL_DEBUG, "I2C GCOEF4_0 write Success\r\n");
return true;
}
bool AK9757_Set_CTL1_9_Parameter(void)
static bool AK9757W_Set_XCOEF4_0_Parameter(void)
{
int error;
uint8_t i;
memcpy(&pHandler->Cntl_Info.CNTL_Buff[0], &default_cntl_reg_data[0], sizeof(default_cntl_reg_data));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &pHandler->Cntl_Info.CNTL_Buff[0], sizeof(default_cntl_reg_data));
memcpy(&pHandler->Xcoef_Info.XCOEF_Buff[0], &default_xcoef_reg_data[1], (sizeof(default_xcoef_reg_data)-1));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &default_xcoef_reg_data[0], sizeof(default_xcoef_reg_data));
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C CNTL1~9 write Error %d\r\n", error);
dbg_printf(LOG_LEVEL_DEBUG, "I2C XCOEF4_0 write Error %d\r\n", error);
return false;
}
dbg_printf(LOG_LEVEL_DEBUG, "I2C XCOEF4_0 write Success\r\n");
return true;
}
static bool AK9757W_Set_IR_TS_IT_Parameter(void)
{
int error;
uint8_t i;
memcpy(&pHandler->IR_TS_IT_Info.IR_TS_IT_Buff[0], &default_gir_oir_gts_ots_git_reg_data[1], (sizeof(default_gir_oir_gts_ots_git_reg_data)-1));
error = I2C_Master_Write(TEMP_I2C_ADDRESS, &default_gir_oir_gts_ots_git_reg_data[0], sizeof(default_gir_oir_gts_ots_git_reg_data));
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C IR_TS_IT write Error %d\r\n", error);
return false;
}
dbg_printf(LOG_LEVEL_DEBUG, "I2C IR_TS_IT write Success\r\n");
return true;
}
@ -251,7 +372,10 @@ bool AK9757_Set_CTL1_9_Parameter(void)
bool AK9757_Get_SensorID(void)
bool AK9757W_Get_SensorID(void)
{
int error;
uint8_t TxBuff;
@ -268,4 +392,14 @@ bool AK9757_Get_SensorID(void)
dbg_printf(LOG_LEVEL_DEBUG, "Read ChipID %XH\r\n", AK9757W_Handler.SensorID);
return true;
}
static void AK9757W_Next_Step(AK9757W_STEP nextStep)
{
AK9757W_Handler.PreStep = AK9757W_Handler.Step;
AK9757W_Handler.Step = nextStep;
}

@ -18,6 +18,6 @@ bool AK9757W_Initialization(void);
bool AK9757_Get_SensorID(void);
bool AK9757_Set_Mode(AK9757W_MODE mode);
bool AK9757_Set_AD_OutputDataTyte(AK9757W_IR_ADC_INVERT type);
bool AK9757_Set_CTL1_9_Parameter(void);
#endif

@ -185,6 +185,14 @@
#define TWO_POW_M10 0.000976562500000
#define TWO_POW_M23 0.000000119209290
#define TWO_POW_M13 0.000061035156250
typedef enum _ak9757w_mode
{
AK9757W_MODE_STAND_BY_MODE = 0,
@ -207,7 +215,11 @@ typedef enum _ak9757w_step
STEP_CHECK_ID_READ,
STEP_CHECK_ID_POWER_OFF,
STEP_WRITE_CNTL1_9,
STEP_WRITE_FCOEF4_0,
STEP_WRITE_GCOEF4_0,
STEP_WRITE_XCOEF4_0,
STEP_WRITE_IR_TS_IT,
STEP_WRITE_WAIT,
STEP_ERROR,
}AK9757W_STEP;
@ -219,7 +231,6 @@ typedef union
{
struct
{
uint8_t get_addr;
uint8_t cntl1;
uint8_t cntl2;
uint8_t cntl3;
@ -230,22 +241,161 @@ typedef union
uint8_t cntl8;
uint8_t cntl9;
}CNTL;
uint8_t CNTL_Buff[10];
uint8_t CNTL_Buff[9];
}CNTL_INFO;
typedef union
{
struct
{
uint8_t fcoef4_l;
uint8_t fcoef4_h;
uint8_t fcoef4_ex;
uint8_t fcoef3_l;
uint8_t fcoef3_h;
uint8_t fcoef3_ex;
uint8_t fcoef2_l;
uint8_t fcoef2_h;
uint8_t fcoef2_ex;
uint8_t fcoef1_l;
uint8_t fcoef1_h;
uint8_t fcoef1_ex;
uint8_t fcoef0_l;
uint8_t fcoef0_h;
}FCOEF;
uint8_t FCOEF_Buff[14];
}FCOEF_INFO;
typedef union
{
struct
{
uint8_t gcoef4_l;
uint8_t gcoef4_h;
uint8_t gcoef4_ex;
uint8_t gcoef3_l;
uint8_t gcoef3_h;
uint8_t gcoef3_ex;
uint8_t gcoef2_l;
uint8_t gcoef2_h;
uint8_t gcoef2_ex;
uint8_t gcoef1_l;
uint8_t gcoef1_h;
uint8_t gcoef1_ex;
uint8_t gcoef0_l;
uint8_t gcoef0_h;
}GCOEF;
uint8_t GCOEF_Buff[14];
}GCOEF_INFO;
typedef union
{
struct
{
uint8_t addr;
uint8_t xcoef4_l;
uint8_t xcoef4_h;
uint8_t xcoef4_ex;
uint8_t xcoef3_l;
uint8_t xcoef3_h;
uint8_t xcoef3_ex;
uint8_t xcoef2_l;
uint8_t xcoef2_h;
uint8_t xcoef2_ex;
uint8_t xcoef1_l;
uint8_t xcoef1_h;
uint8_t xcoef1_ex;
uint8_t xcoef0_l;
uint8_t xcoef0_h;
}XCOEF;
uint8_t XCOEF_Buff[14];
}XCOEF_INFO;
typedef union
{
struct
{
uint8_t reserved;
uint8_t gir_l;
uint8_t gir_h;
uint8_t oir_l;
uint8_t oir_h;
uint8_t gts;
uint8_t ots_l;
uint8_t ots_h;
uint8_t git;
}XCOEF;
uint8_t IR_TS_IT_Buff[9];
}IR_TS_IT_INFO;
#pragma pack(push, 1)
typedef struct
{
uint16_t FCOEF0;
uint16_t FCOEF1;
uint8_t FCOEF1_Ex;
uint16_t FCOEF2;
uint8_t FCOEF2_Ex;
uint16_t FCOEF3;
uint8_t FCOEF3_Ex;
uint16_t FCOEF4;
uint8_t FCOEF4_Ex;
uint16_t GCOEF0;
uint16_t GCOEF1;
uint8_t GCOEF1_Ex;
uint16_t GCOEF2;
uint8_t GCOEF2_Ex;
uint16_t GCOEF3;
uint8_t GCOEF3_Ex;
uint16_t GCOEF4;
uint8_t GCOEF4_Ex;
uint16_t XCOEF0;
uint16_t XCOEF1;
uint8_t XCOEF1_Ex;
uint16_t XCOEF2;
uint8_t XCOEF2_Ex;
uint16_t XCOEF3;
uint8_t XCOEF3_Ex;
uint16_t XCOEF4;
uint8_t XCOEF4_Ex;
uint8_t Reserved;
uint16_t GIR;
uint16_t OIR;
uint8_t GTS;
uint16_t OTS;
uint8_t GIT;
}TEMP_CAL_PARAMETER;
#pragma pack(pop)
typedef struct _ak9757w_handler
{
bool isInitComplete;
uint32_t SensorID;
CNTL_INFO Cntl_Info;
CNTL_INFO Cntl_Info;
FCOEF_INFO Fcoef_Info;
GCOEF_INFO Gcoef_Info;
XCOEF_INFO Xcoef_Info;
IR_TS_IT_INFO IR_TS_IT_Info;
TEMP_CAL_PARAMETER Calculation_Parameter;
AK9757W_STEP PreStep;
AK9757W_STEP Step;
uint32_t TickCount;
double TS;
double GIR;
double IR;
uint32_t TickCount;
}AK9757W_HANDLER;

File diff suppressed because one or more lines are too long

@ -154,7 +154,7 @@
<Type>0</Type>
<LineNumber>327</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>14270</Address>
<Address>19268</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
@ -165,17 +165,54 @@
<ExecCommand></ExecCommand>
<Expression>\\AKM_Temperature_Demo\../Application/app_cli.c\327</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>82</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>9864</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Application\app_oled.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\AKM_Temperature_Demo\../Application/app_oled.c\82</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>283</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>4496</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Application\sensor\ak9757w.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\AKM_Temperature_Demo\../Application/sensor/ak9757w.c\283</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>Tx_RingBuffer</ItemText>
<ItemText>pHandler</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>pRingbuffer</ItemText>
<ItemText>default_cntl_reg_data</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>RxBuff</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
@ -240,7 +277,7 @@
<Group>
<GroupName>Application</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
@ -388,6 +425,30 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>13</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Application\app_oled.c</PathWithFileName>
<FilenameWithoutPath>app_oled.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>14</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Application\app_gpio.c</PathWithFileName>
<FilenameWithoutPath>app_gpio.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@ -398,7 +459,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>13</FileNumber>
<FileNumber>15</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -418,7 +479,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>14</FileNumber>
<FileNumber>16</FileNumber>
<FileType>2</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -438,7 +499,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>15</FileNumber>
<FileNumber>17</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -450,7 +511,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>16</FileNumber>
<FileNumber>18</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -462,7 +523,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>17</FileNumber>
<FileNumber>19</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -474,7 +535,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>18</FileNumber>
<FileNumber>20</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -486,7 +547,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>19</FileNumber>
<FileNumber>21</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -498,7 +559,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>20</FileNumber>
<FileNumber>22</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -510,7 +571,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>21</FileNumber>
<FileNumber>23</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -522,7 +583,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>22</FileNumber>
<FileNumber>24</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -534,7 +595,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>23</FileNumber>
<FileNumber>25</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -546,7 +607,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>24</FileNumber>
<FileNumber>26</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -558,7 +619,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>25</FileNumber>
<FileNumber>27</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -570,7 +631,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>26</FileNumber>
<FileNumber>28</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -582,7 +643,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>27</FileNumber>
<FileNumber>29</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -594,7 +655,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>28</FileNumber>
<FileNumber>30</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -606,7 +667,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>29</FileNumber>
<FileNumber>31</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -618,7 +679,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>30</FileNumber>
<FileNumber>32</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -630,7 +691,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>31</FileNumber>
<FileNumber>33</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -642,7 +703,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>32</FileNumber>
<FileNumber>34</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -654,7 +715,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>33</FileNumber>
<FileNumber>35</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -666,7 +727,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>34</FileNumber>
<FileNumber>36</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -678,7 +739,7 @@
</File>
<File>
<GroupNumber>4</GroupNumber>
<FileNumber>35</FileNumber>
<FileNumber>37</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -698,7 +759,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>36</FileNumber>
<FileNumber>38</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -710,7 +771,7 @@
</File>
<File>
<GroupNumber>5</GroupNumber>
<FileNumber>37</FileNumber>
<FileNumber>39</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -724,13 +785,13 @@
<Group>
<GroupName>Sensor</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>6</GroupNumber>
<FileNumber>38</FileNumber>
<FileNumber>40</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -750,7 +811,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>39</FileNumber>
<FileNumber>41</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -762,7 +823,7 @@
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>40</FileNumber>
<FileNumber>42</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@ -774,7 +835,7 @@
</File>
<File>
<GroupNumber>7</GroupNumber>
<FileNumber>41</FileNumber>
<FileNumber>43</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>

@ -443,6 +443,16 @@
<FileType>1</FileType>
<FilePath>..\Application\app_cli.c</FilePath>
</File>
<File>
<FileName>app_oled.c</FileName>
<FileType>1</FileType>
<FilePath>..\Application\app_oled.c</FilePath>
</File>
<File>
<FileName>app_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\Application\app_gpio.c</FilePath>
</File>
</Files>
</Group>
<Group>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save