Added BK1080 initialisation.

This commit is contained in:
Dual Tachyon 2023-08-10 11:46:22 +01:00
parent 994eb4f235
commit 0d1e0a084c
6 changed files with 94 additions and 1 deletions

View File

@ -17,6 +17,7 @@ OBJS += $(BLOB_OVERLAY).o
# Drivers
OBJS += driver/adc.o
OBJS += driver/bk1080.o
OBJS += driver/crc.o
OBJS += driver/eeprom.o
OBJS += driver/flash.o

View File

@ -21,6 +21,7 @@
#include "bsp/dp32g030/saradc.h"
#include "bsp/dp32g030/syscon.h"
#include "driver/adc.h"
#include "driver/bk1080.h"
#include "driver/crc.h"
#include "driver/flash.h"
#include "driver/gpio.h"
@ -315,7 +316,7 @@ void BOARD_Init(void)
BOARD_GPIO_Init();
BOARD_ADC_Init();
ST7565_Init();
//BK1080_Init(0, false);
BK1080_Init(0, false);
CRC_Init();
}

15
driver/bk1080-regs.h Executable file
View File

@ -0,0 +1,15 @@
#ifndef BK1080_REGS_H
#define BK1080_REGS_H
enum BK1080_REGISTER_t {
REG_00 = 0x00U,
REG_02_POWER_CONFIGURATION = 0x02U,
REG_03_CHANNEL = 0x03U,
REG_05_SYSTEM_CONFIGURATION2 = 0x03U,
REG_25_INTERNAL = 0x25U,
};
typedef enum BK1080_REGISTER_t BK1080_REGISTER_t;
#endif

60
driver/bk1080.c Executable file
View File

@ -0,0 +1,60 @@
#include "bsp/dp32g030/gpio.h"
#include "bk1080.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/system.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
static const uint16_t BK1080_RegisterTable[] = {
0x0008, 0x1080, 0x0201, 0x0000,
0x40C0, 0x0A1F, 0x002E, 0x02FF,
0x5B11, 0x0000, 0x411E, 0x0000,
0xCE00, 0x0000, 0x0000, 0x1000,
0x3197, 0x0000, 0x13FF, 0x9852,
0x0000, 0x0000, 0x0008, 0x0000,
0x51E1, 0xA8BC, 0x2645, 0x00E4,
0x1CD8, 0x3A50, 0xEAE0, 0x3000,
0x0200, 0x0000,
};
static bool gIsInitBK1080;
void BK1080_Init(uint16_t Channel, bool bDoScan)
{
uint8_t i;
if (bDoScan) {
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
if (!gIsInitBK1080) {
for (i = 0; i < ARRAY_SIZE(BK1080_RegisterTable); i++) {
BK1080_WriteRegister(i, BK1080_RegisterTable[i]);
}
SYSTEM_DelayMs(250);
BK1080_WriteRegister(REG_25_INTERNAL, 0xA83C);
BK1080_WriteRegister(REG_25_INTERNAL, 0xA8BC);
SYSTEM_DelayMs(60);
gIsInitBK1080 = true;
} else {
BK1080_WriteRegister(REG_02_POWER_CONFIGURATION, 0x0201);
}
BK1080_WriteRegister(REG_05_SYSTEM_CONFIGURATION2, 0x0A5F);
BK1080_WriteRegister(REG_03_CHANNEL, Channel - 760);
SYSTEM_DelayMs(10);
BK1080_WriteRegister(REG_03_CHANNEL, (Channel - 760) | 0x8000);
} else {
BK1080_WriteRegister(REG_02_POWER_CONFIGURATION, 0x0241);
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
}
}
void BK1080_WriteRegister(BK1080_REGISTER_t Register, uint16_t Value)
{
I2C_Start();
I2C_Write(0x80);
I2C_Write(Register << 1);
I2C_WriteBuffer(&Value, sizeof(Value));
I2C_Stop();
}

12
driver/bk1080.h Executable file
View File

@ -0,0 +1,12 @@
#ifndef DRIVER_BK1080_H
#define DRIVER_BK1080_H
#include <stdbool.h>
#include <stdint.h>
#include "driver/bk1080-regs.h"
void BK1080_Init(uint16_t Frequency, bool bDoScan);
void BK1080_WriteRegister(BK1080_REGISTER_t Register, uint16_t Value);
#endif

View File

@ -24,6 +24,10 @@ enum GPIOA_PINS {
GPIOA_PIN_I2C_SDA = 11,
};
enum GPIOB_PINS {
GPIOB_PIN_BK1080 = 15,
};
enum GPIOC_PINS {
GPIOC_PIN_BK4819_0 = 0,
GPIOC_PIN_BK4819_1 = 1,