142 lines
3.4 KiB
C
142 lines
3.4 KiB
C
/*
|
|
* @Author: DaMing zxm5337@163.com
|
|
* @Date: 2024-04-03 10:48:06
|
|
* @LastEditors: 张小明 zxm5337@163.com
|
|
* @LastEditTime: 2024-05-22 21:46:30
|
|
* @FilePath: \Proxi_CheckBoard\User\App\hc595display.c
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include "hc595display.h"
|
|
#include "motor.h"
|
|
#include "dac.h"
|
|
|
|
hc595display_t hc595display_A;
|
|
hc595display_t hc595display_B;
|
|
// msb
|
|
// const uint8_t seg_code[10] = {0xe7, 0x21, 0xcb, 0x6b, 0x2d, 0x6e, 0xee, 0x23, 0xef, 0x6f};
|
|
// lsb
|
|
const uint8_t seg_code[10] = {0xe7, 0x84, 0xd3, 0xd6, 0xb4, 0x76, 0x77, 0xc4, 0xf7, 0xf6};
|
|
|
|
static uint32_t fun_get_led(uint16_t code)
|
|
{
|
|
uint8_t i;
|
|
uint16_t temp1 = 0x0001;
|
|
int32_t temp2 = 0;
|
|
uint32_t result = 0;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
{
|
|
if (code & temp1)
|
|
{
|
|
temp2 = 0x00000001;
|
|
temp2 <<= 31 - i * 2;
|
|
result |= temp2;
|
|
|
|
temp2 = 0x000000001;
|
|
temp2 <<= 30 - i * 2;
|
|
// temp2 >>= 1;
|
|
result &= ~temp2;
|
|
}
|
|
else
|
|
{
|
|
temp2 = 0x00000001;
|
|
temp2 <<= 31 - i * 2;
|
|
result &= ~temp2;
|
|
|
|
temp2 = 0x000000001;
|
|
temp2 <<= 30 - i * 2;
|
|
// temp2 >>= 1;
|
|
result |= temp2;
|
|
}
|
|
temp1 <<= 1;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static void fun_ctr_595_lat(uint8_t *index, BOOL en)
|
|
{
|
|
if (!index)
|
|
return;
|
|
|
|
if (*index == RESULT_A)
|
|
{
|
|
if (en == TRUE)
|
|
RESULT_A_LAT_H();
|
|
else if (en == FALSE)
|
|
RESULT_A_LAT_L();
|
|
}
|
|
else if (*index == RESULT_B)
|
|
{
|
|
if (en == TRUE)
|
|
RESULT_B_LAT_H();
|
|
else if (en == FALSE)
|
|
RESULT_B_LAT_L();
|
|
}
|
|
}
|
|
|
|
void fun_ini_595_display(hc595display_t *hc595display)
|
|
{
|
|
if (!hc595display)
|
|
return;
|
|
|
|
uint8_t *index = &hc595display->index;
|
|
|
|
memset(hc595display, 0, sizeof(hc595display_t));
|
|
|
|
if (hc595display == &hc595display_A)
|
|
*index = RESULT_A;
|
|
else if (hc595display == &hc595display_B)
|
|
*index = RESULT_B;
|
|
}
|
|
|
|
static void fun_get_display_step(hc595display_t *hc595display)
|
|
{
|
|
|
|
if (hc595display == NULL)
|
|
return;
|
|
|
|
prox_swith_pwr_t *prox_swith_pwr;
|
|
|
|
if (hc595display == &hc595display_A)
|
|
{
|
|
prox_swith_pwr = &prox_swith_pwr_A;
|
|
}
|
|
else if (hc595display == &hc595display_B)
|
|
{
|
|
prox_swith_pwr = &prox_swith_pwr_B;
|
|
}
|
|
|
|
if (prox_swith_pwr->voltage_sv == 8200)
|
|
hc595display->step = 1;
|
|
else if (prox_swith_pwr->voltage_sv == 6970)
|
|
{
|
|
hc595display->err_code = 0;
|
|
hc595display->step = 2;
|
|
}
|
|
else if (prox_swith_pwr->voltage_sv == 9020)
|
|
hc595display->step = 3;
|
|
else
|
|
hc595display->step = 0;
|
|
}
|
|
|
|
void fun_ctr_595_display(hc595display_t *hc595display)
|
|
{
|
|
if (!hc595display)
|
|
return;
|
|
|
|
uint8_t *index = &hc595display->index;
|
|
uint8_t *step = &hc595display->step;
|
|
uint16_t *err_code = &hc595display->err_code;
|
|
uint32_t *reg = &hc595display->reg;
|
|
|
|
fun_get_display_step(hc595display);
|
|
*reg = fun_get_led(*err_code);
|
|
*reg |= seg_code[*step];
|
|
*reg &= 0xfffff0ff;
|
|
fun_ctr_595_lat(index, FALSE);
|
|
HAL_SPI_Transmit(&hspi1, (uint8_t *)reg, 4, SPI1_TIMEOUT_VALUE);
|
|
fun_ctr_595_lat(index, TRUE);
|
|
}
|