Renamed BK4819 GPIO pins.

This commit is contained in:
Dual Tachyon 2023-08-12 21:24:18 +01:00
parent 25769c44d8
commit b92d66a012
2 changed files with 31 additions and 31 deletions

View File

@ -24,9 +24,9 @@ uint16_t gBK4819_GpioOutState;
void BK4819_Init(void)
{
GPIO_SetBit(&GPIOC->DATA, 0);
GPIO_SetBit(&GPIOC->DATA, 1);
GPIO_SetBit(&GPIOC->DATA, 2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
BK4819_WriteRegister(BK4819_REG_00, 0x8000);
BK4819_WriteRegister(BK4819_REG_00, 0x0000);
@ -71,10 +71,10 @@ static uint16_t BK4819_ReadU16(void)
Value = 0;
for (i = 0; i < 16; i++) {
Value <<= 1;
Value |= GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
Value |= GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
}
PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_DISABLE;
@ -87,55 +87,55 @@ uint16_t BK4819_GetRegister(BK4819_REGISTER_t Register)
{
uint16_t Value;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
BK4819_WriteU8(Register | 0x80);
Value = BK4819_ReadU16();
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
return Value;
}
void BK4819_WriteRegister(BK4819_REGISTER_t Register, uint16_t Data)
{
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
BK4819_WriteU8(Register);
SYSTICK_DelayUs(1);
BK4819_WriteU16(Data);
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_0);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
}
void BK4819_WriteU8(uint8_t Data)
{
uint8_t i;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
for (i = 0; i < 8; i++) {
if ((Data & 0x80U) == 0) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
} else {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
}
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
Data <<= 1;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
}
}
@ -144,18 +144,18 @@ void BK4819_WriteU16(uint16_t Data)
{
uint8_t i;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
for (i = 0; i < 16; i++) {
if ((Data & 0x8000U) == 0U) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
} else {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
}
SYSTICK_DelayUs(1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
Data <<= 1;
SYSTICK_DelayUs(1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_1);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
SYSTICK_DelayUs(1);
}
}

View File

@ -47,9 +47,9 @@ enum GPIOB_PINS {
};
enum GPIOC_PINS {
GPIOC_PIN_BK4819_0 = 0,
GPIOC_PIN_BK4819_1 = 1,
GPIOC_PIN_BK4819_2 = 2,
GPIOC_PIN_BK4819_SCN = 0,
GPIOC_PIN_BK4819_SCL = 1,
GPIOC_PIN_BK4819_SDA = 2,
};
void GPIO_ClearBit(volatile uint32_t *pReg, uint8_t Bit);