Changed MCU init code to match the one from mcu module more closely.
More documentation for the color range adjustment and small cleanup.
This commit is contained in:
parent
83f8a2d1e7
commit
e70f80d408
|
@ -55,14 +55,6 @@ typedef enum
|
|||
|
||||
|
||||
|
||||
void MCU_init(void);
|
||||
|
||||
bool MCU_setEventMask(u32 mask);
|
||||
|
||||
u32 MCU_getEvents(u32 mask);
|
||||
|
||||
u32 MCU_waitEvents(u32 mask);
|
||||
|
||||
u8 MCU_readReg(McuReg reg);
|
||||
|
||||
bool MCU_writeReg(McuReg reg, u8 data);
|
||||
|
@ -71,6 +63,14 @@ bool MCU_readRegBuf(McuReg reg, u8 *out, u32 size);
|
|||
|
||||
bool MCU_writeRegBuf(McuReg reg, const u8 *const in, u32 size);
|
||||
|
||||
void MCU_init(void);
|
||||
|
||||
bool MCU_setEventMask(u32 mask);
|
||||
|
||||
u32 MCU_getEvents(u32 mask);
|
||||
|
||||
u32 MCU_waitEvents(u32 mask);
|
||||
|
||||
|
||||
static inline u8 MCU_getBatteryLevel(void)
|
||||
{
|
||||
|
|
|
@ -95,20 +95,25 @@ static void lgyFbDmaIrqHandler(UNUSED u32 intSource)
|
|||
atomic_store_explicit(&g_frameReady, true, memory_order_relaxed);
|
||||
}
|
||||
|
||||
static void setScaleMatrixTop(u32 len, u32 patt, const s16 matrix[6][8])
|
||||
static void setScaleMatrixTop(u32 len, u32 patt, const s16 *const matrix)
|
||||
{
|
||||
REG_LGYFB_TOP_V_LEN = len - 1;
|
||||
REG_LGYFB_TOP_V_PATT = patt;
|
||||
REG_LGYFB_TOP_H_LEN = len - 1;
|
||||
REG_LGYFB_TOP_H_PATT = patt;
|
||||
|
||||
for(u32 i = 0; i < 6; i++)
|
||||
for(u32 y = 0; y < 6; y++)
|
||||
{
|
||||
for(u32 j = 0; j < len; j++)
|
||||
for(u32 x = 0; x < len; x++)
|
||||
{
|
||||
const s16 tmp = matrix[i][j];
|
||||
REG_LGYFB_TOP_V_MATRIX[i][j] = tmp * 0xFF / 0xF8 + 8;
|
||||
REG_LGYFB_TOP_H_MATRIX[i][j] = tmp + 8;
|
||||
const s16 tmp = matrix[len * y + x];
|
||||
|
||||
// Correct the color range using the scale matrix hardware.
|
||||
// For example when converting RGB555 to RGB8 LgyFb lazily shifts the 5 bits up
|
||||
// so 0b00011111 becomes 0b11111000. This creates wrong spacing between colors.
|
||||
// TODO: What is the "+ 8" good for?
|
||||
REG_LGYFB_TOP_V_MATRIX[y][x] = tmp * 0xFF / 0xF8 + 8;
|
||||
REG_LGYFB_TOP_H_MATRIX[y][x] = tmp + 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,34 +142,32 @@ void LGYFB_init(void)
|
|||
*
|
||||
* Note: At scanline start the in FIFO is all filled with the first pixel.
|
||||
*/
|
||||
static const s16 scaleMatrix[6][8] =
|
||||
static const s16 scaleMatrix[6 * 6] =
|
||||
{
|
||||
// Original from AGB_FIRM.
|
||||
/*{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-3]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-2]
|
||||
{ 0, 0x2000, 0x4000, 0, 0x2000, 0x4000, 0, 0}, // in[-1]
|
||||
{0x4000, 0x2000, 0, 0x4000, 0x2000, 0, 0, 0}, // in[0]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[1]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}*/ // in[2]
|
||||
/* 0, 0, 0, 0, 0, 0, // in[-3]
|
||||
0, 0, 0, 0, 0, 0, // in[-2]
|
||||
0, 0x2000, 0x4000, 0, 0x2000, 0x4000, // in[-1]
|
||||
0x4000, 0x2000, 0, 0x4000, 0x2000, 0, // in[0]
|
||||
0, 0, 0, 0, 0, 0, // in[1]
|
||||
0, 0, 0, 0, 0, 0*/ // in[2]
|
||||
// out[0] out[1] out[2] out[3] out[4] out[5] out[6] out[7]
|
||||
|
||||
// Razor sharp (pixel duplication).
|
||||
/*{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-3]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-2]
|
||||
{ 0, 0, 0x4000, 0, 0, 0x4000, 0, 0}, // in[-1]
|
||||
{0x4000, 0x4000, 0, 0x4000, 0x4000, 0, 0, 0}, // in[0]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[1]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}*/ // in[2]
|
||||
// out[0] out[1] out[2] out[3] out[4] out[5] out[6] out[7]
|
||||
/* 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0x4000, 0, 0, 0x4000,
|
||||
0x4000, 0x4000, 0, 0x4000, 0x4000, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0*/
|
||||
|
||||
// Sharp interpolated.
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-3]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[-2]
|
||||
{ 0, 0, 0x2000, 0, 0, 0x2000, 0, 0}, // in[-1]
|
||||
{0x4000, 0x4000, 0x2000, 0x4000, 0x4000, 0x2000, 0, 0}, // in[0]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0}, // in[1]
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0} // in[2]
|
||||
// out[0] out[1] out[2] out[3] out[4] out[5] out[6] out[7]
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0x2000, 0, 0, 0x2000,
|
||||
0x4000, 0x4000, 0x2000, 0x4000, 0x4000, 0x2000,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0
|
||||
};
|
||||
setScaleMatrixTop(6, 0b00011011, scaleMatrix);
|
||||
|
||||
|
|
|
@ -30,6 +30,26 @@ static u32 g_events = 0;
|
|||
|
||||
static void mcuIrqHandler(UNUSED u32 intSource);
|
||||
|
||||
u8 MCU_readReg(McuReg reg)
|
||||
{
|
||||
return I2C_readReg(I2C_DEV_CTR_MCU, reg);
|
||||
}
|
||||
|
||||
bool MCU_writeReg(McuReg reg, u8 data)
|
||||
{
|
||||
return I2C_writeReg(I2C_DEV_CTR_MCU, reg, data);
|
||||
}
|
||||
|
||||
bool MCU_readRegBuf(McuReg reg, u8 *out, u32 size)
|
||||
{
|
||||
return I2C_readRegBuf(I2C_DEV_CTR_MCU, reg, out, size);
|
||||
}
|
||||
|
||||
bool MCU_writeRegBuf(McuReg reg, const u8 *const in, u32 size)
|
||||
{
|
||||
return I2C_writeRegBuf(I2C_DEV_CTR_MCU, reg, in, size);
|
||||
}
|
||||
|
||||
void MCU_init(void)
|
||||
{
|
||||
static bool inited = false;
|
||||
|
@ -38,13 +58,14 @@ void MCU_init(void)
|
|||
|
||||
I2C_init();
|
||||
|
||||
atomic_store_explicit(&g_mcuIrq, true, memory_order_relaxed);
|
||||
(void)MCU_getEvents(0xFFFFFFFFu);
|
||||
|
||||
MCU_setEventMask(0xC0BF3F80);
|
||||
// Configure GPIO for MCU event IRQs
|
||||
GPIO_config(GPIO_3_MCU, GPIO_INPUT | GPIO_EDGE_FALLING | GPIO_IRQ_ENABLE);
|
||||
IRQ_registerIsr(IRQ_CTR_MCU, 14, 0, mcuIrqHandler);
|
||||
|
||||
atomic_store_explicit(&g_mcuIrq, true, memory_order_relaxed);
|
||||
(void)MCU_getEvents(0);
|
||||
|
||||
MCU_setEventMask(0xC0BF3F80);
|
||||
}
|
||||
|
||||
static void mcuIrqHandler(UNUSED u32 intSource)
|
||||
|
@ -87,23 +108,3 @@ u32 MCU_waitEvents(u32 mask)
|
|||
|
||||
return events;
|
||||
}
|
||||
|
||||
u8 MCU_readReg(McuReg reg)
|
||||
{
|
||||
return I2C_readReg(I2C_DEV_CTR_MCU, reg);
|
||||
}
|
||||
|
||||
bool MCU_writeReg(McuReg reg, u8 data)
|
||||
{
|
||||
return I2C_writeReg(I2C_DEV_CTR_MCU, reg, data);
|
||||
}
|
||||
|
||||
bool MCU_readRegBuf(McuReg reg, u8 *out, u32 size)
|
||||
{
|
||||
return I2C_readRegBuf(I2C_DEV_CTR_MCU, reg, out, size);
|
||||
}
|
||||
|
||||
bool MCU_writeRegBuf(McuReg reg, const u8 *const in, u32 size)
|
||||
{
|
||||
return I2C_writeRegBuf(I2C_DEV_CTR_MCU, reg, in, size);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue