Display write and setPosition
This commit is contained in:
@@ -37,32 +37,50 @@ int32_t ILI9341::init() {
|
|||||||
// Wrong ID
|
// Wrong ID
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
uint8_t idn[3];
|
uint8_t idn[3];
|
||||||
errors += readReg8(0xDA, idn);
|
errors += readReg8(0xDA, idn);
|
||||||
errors += readReg8(0xDB, idn+1);
|
errors += readReg8(0xDB, idn+1);
|
||||||
errors += readReg8(0xDC, idn+2);
|
errors += readReg8(0xDC, idn+2);
|
||||||
writeBuffer(0x11, nullptr, 0);
|
*/
|
||||||
|
errors += writeBuffer(0x11, nullptr, 0); // Sleep out
|
||||||
vTaskDelay(5);
|
vTaskDelay(5);
|
||||||
uint8_t buf[720];
|
/*
|
||||||
uint8_t pasetBuf[4];
|
|
||||||
for(uint16_t i = 0; i<320; i++){
|
|
||||||
pasetBuf[0] = (i>>8);
|
|
||||||
pasetBuf[1] = i;
|
|
||||||
pasetBuf[2] = 319>>8;
|
|
||||||
pasetBuf[3] = 319;
|
|
||||||
writeBuffer(0x2B, pasetBuf, 4);
|
|
||||||
for(uint32_t j = 0; j<720; j++){
|
|
||||||
buf[j] = (j%64)<<2;
|
|
||||||
}
|
|
||||||
writeBuffer(0x2C, buf, 720);
|
|
||||||
}
|
|
||||||
writeBuffer(0x29, nullptr, 0);
|
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
errors += readReg32(0x09, &status);
|
errors += readReg32(0x09, &status);
|
||||||
errors += hLedPwm->setDuty(1);
|
*/
|
||||||
|
errors += writeBuffer(0x29, nullptr, 0); // Display on
|
||||||
|
setBacklight(0);
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ILI9341::setPosition(uint16_t xPosition, uint16_t yPosition, uint16_t xSize, uint16_t ySize) {
|
||||||
|
int32_t errors = 0;
|
||||||
|
uint8_t casetBuf[4];
|
||||||
|
casetBuf[0] = (xPosition>>8);
|
||||||
|
casetBuf[1] = xPosition;
|
||||||
|
casetBuf[2] = ((xPosition+xSize-1)>>8);
|
||||||
|
casetBuf[3] = (xPosition+xSize-1);
|
||||||
|
errors += writeBuffer(0x2A, casetBuf, 4);
|
||||||
|
uint8_t pasetBuf[4];
|
||||||
|
pasetBuf[0] = (yPosition>>8);
|
||||||
|
pasetBuf[1] = yPosition;
|
||||||
|
pasetBuf[2] = ((yPosition+ySize-1)>>8);
|
||||||
|
pasetBuf[3] = (yPosition+ySize-1);
|
||||||
|
errors += writeBuffer(0x2B, pasetBuf, 4);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ILI9341::write(uint8_t* buffer, uint32_t length) {
|
||||||
|
return writeBuffer(0x2C, buffer, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ILI9341::setBacklight(float backlight) {
|
||||||
|
return hLedPwm->setDuty(backlight);
|
||||||
|
}
|
||||||
|
|
||||||
// Private methods
|
// Private methods
|
||||||
|
|
||||||
int32_t ILI9341::readReg8(uint8_t command, uint8_t* reg) {
|
int32_t ILI9341::readReg8(uint8_t command, uint8_t* reg) {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public:
|
|||||||
ILI9341(SPI_Peripheral* hSpi, GPIO_Pin* nssPin, GPIO_Pin* hResetPin, GPIO_Pin* hDcrsPin, PWM_Pin* hLedPwm);
|
ILI9341(SPI_Peripheral* hSpi, GPIO_Pin* nssPin, GPIO_Pin* hResetPin, GPIO_Pin* hDcrsPin, PWM_Pin* hLedPwm);
|
||||||
virtual ~ILI9341();
|
virtual ~ILI9341();
|
||||||
int32_t init();
|
int32_t init();
|
||||||
|
int32_t setPosition(uint16_t xPosition, uint16_t yPosition, uint16_t xSize, uint16_t ySize);
|
||||||
|
int32_t write(uint8_t* buffer, uint32_t length);
|
||||||
|
int32_t setBacklight(float backlight);
|
||||||
private:
|
private:
|
||||||
int32_t readReg8(uint8_t command, uint8_t* reg);
|
int32_t readReg8(uint8_t command, uint8_t* reg);
|
||||||
int32_t readReg24(uint8_t command, uint32_t* reg);
|
int32_t readReg24(uint8_t command, uint32_t* reg);
|
||||||
@@ -30,8 +33,8 @@ private:
|
|||||||
GPIO_Pin* hResetPin;
|
GPIO_Pin* hResetPin;
|
||||||
GPIO_Pin* hDcrsPin;
|
GPIO_Pin* hDcrsPin;
|
||||||
PWM_Pin* hLedPwm;
|
PWM_Pin* hLedPwm;
|
||||||
uint8_t txBuffer[16384];
|
uint8_t txBuffer[16];
|
||||||
uint8_t rxBuffer[16384];
|
uint8_t rxBuffer[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SRC_COMPONENTS_ILI9341_HPP_ */
|
#endif /* SRC_COMPONENTS_ILI9341_HPP_ */
|
||||||
|
|||||||
@@ -22,16 +22,26 @@ GPIO_Pin_STM32 ledBlue(LD6_GPIO_Port, LD6_Pin);
|
|||||||
//GPIO_Pin_STM32* discoveryLedArray[4] = {&ledOrange, &ledGreen, &ledRed, &ledBlue};
|
//GPIO_Pin_STM32* discoveryLedArray[4] = {&ledOrange, &ledGreen, &ledRed, &ledBlue};
|
||||||
BinLeds discoveryLeds((GPIO_Pin*[]){&ledOrange, &ledGreen, &ledRed, &ledBlue}, 4);
|
BinLeds discoveryLeds((GPIO_Pin*[]){&ledOrange, &ledGreen, &ledRed, &ledBlue}, 4);
|
||||||
|
|
||||||
SPI_Peripheral_STM32 spi_a(&hspi5, 100);
|
SPI_Peripheral_STM32 spi_a(&hspi5, 1000);
|
||||||
GPIO_Pin_STM32 displayNss(DISPLAY_NSS_GPIO_Port, DISPLAY_NSS_Pin);
|
GPIO_Pin_STM32 displayNss(DISPLAY_NSS_GPIO_Port, DISPLAY_NSS_Pin);
|
||||||
GPIO_Pin_STM32 displayReset(DISPLAY_RESET_GPIO_Port, DISPLAY_RESET_Pin);
|
GPIO_Pin_STM32 displayReset(DISPLAY_RESET_GPIO_Port, DISPLAY_RESET_Pin);
|
||||||
GPIO_Pin_STM32 displayDcrs(DISPLAY_DCRS_GPIO_Port, DISPLAY_DCRS_Pin);
|
GPIO_Pin_STM32 displayDcrs(DISPLAY_DCRS_GPIO_Port, DISPLAY_DCRS_Pin);
|
||||||
PWM_Pin_STM32 displayLed(&htim10, TIM_CHANNEL_1);
|
PWM_Pin_STM32 displayLed(&htim10, TIM_CHANNEL_1);
|
||||||
ILI9341 display(&spi_a, &displayNss, &displayReset, &displayDcrs, &displayLed);
|
ILI9341 display(&spi_a, &displayNss, &displayReset, &displayDcrs, &displayLed);
|
||||||
|
|
||||||
|
uint8_t buffer[19200];
|
||||||
|
|
||||||
void start(){
|
void start(){
|
||||||
spi_a.init();
|
spi_a.init();
|
||||||
display.init();
|
display.init();
|
||||||
|
display.setBacklight(1);
|
||||||
|
for(uint32_t i = 0; i<19200; i++){
|
||||||
|
buffer[i] = 32<<2;
|
||||||
|
}
|
||||||
|
display.setPosition(0, 0, 80, 80);
|
||||||
|
display.write(buffer, 19200);
|
||||||
|
display.setPosition(0, 80, 80, 80);
|
||||||
|
display.write(buffer, 19200);
|
||||||
for(uint32_t i=0; i<16; i++){
|
for(uint32_t i=0; i<16; i++){
|
||||||
discoveryLeds.set(i);
|
discoveryLeds.set(i);
|
||||||
vTaskDelay(1000);
|
vTaskDelay(1000);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void MX_SPI5_Init(void)
|
|||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
hspi5.Init.NSS = SPI_NSS_SOFT;
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
|
|||||||
@@ -440,8 +440,8 @@ SPI1.Direction=SPI_DIRECTION_2LINES
|
|||||||
SPI1.IPParameters=CalculateBaudRate,BaudRatePrescaler,Mode,VirtualType,Direction
|
SPI1.IPParameters=CalculateBaudRate,BaudRatePrescaler,Mode,VirtualType,Direction
|
||||||
SPI1.Mode=SPI_MODE_MASTER
|
SPI1.Mode=SPI_MODE_MASTER
|
||||||
SPI1.VirtualType=VM_MASTER
|
SPI1.VirtualType=VM_MASTER
|
||||||
SPI5.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_64
|
SPI5.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16
|
||||||
SPI5.CalculateBaudRate=1.5 MBits/s
|
SPI5.CalculateBaudRate=6.0 MBits/s
|
||||||
SPI5.Direction=SPI_DIRECTION_2LINES
|
SPI5.Direction=SPI_DIRECTION_2LINES
|
||||||
SPI5.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler
|
SPI5.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler
|
||||||
SPI5.Mode=SPI_MODE_MASTER
|
SPI5.Mode=SPI_MODE_MASTER
|
||||||
|
|||||||
Reference in New Issue
Block a user