Add PWM backlight control to Nokia6610GE8
Add PWM backlight control to Nokia6610GE8 for the Olimex SAM7EX256 board.
This commit is contained in:
parent
911df31d1c
commit
2d7c95d20a
1 changed files with 238 additions and 196 deletions
|
@ -32,11 +32,31 @@
|
||||||
// ******************************************************
|
// ******************************************************
|
||||||
// Pointers to AT91SAM7X256 peripheral data structures
|
// Pointers to AT91SAM7X256 peripheral data structures
|
||||||
// ******************************************************
|
// ******************************************************
|
||||||
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
|
static volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
|
||||||
volatile AT91PS_PIO pPIOB = AT91C_BASE_PIOB;
|
static volatile AT91PS_PIO pPIOB = AT91C_BASE_PIOB;
|
||||||
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI0;
|
static volatile AT91PS_SPI pSPI = AT91C_BASE_SPI0;
|
||||||
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
|
static volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
|
||||||
volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_SPI0;
|
static volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_SPI0;
|
||||||
|
|
||||||
|
/* The PWM backlight control is non-linear on this board.
|
||||||
|
* We pick values here that make it look a bit more linear.
|
||||||
|
*/
|
||||||
|
#define PWM_TOP_VALUE 500
|
||||||
|
#define PWM_BOTTOM_VALUE 200
|
||||||
|
|
||||||
|
#define PWM_VALUE(x) (PWM_BOTTOM_VALUE+(PWM_TOP_VALUE-PWM_BOTTOM_VALUE)*(x)/100)
|
||||||
|
|
||||||
|
/* PWM configuration structure. The LCD Backlight is on PWM1/PB20 ie PWM2/PIN1 in ChibiOS speak */
|
||||||
|
static const PWMConfig pwmcfg = {
|
||||||
|
1000000, /* 1 MHz PWM clock frequency. Ignored as we are using PWM_MCK_DIV_n */
|
||||||
|
1000, /* PWM period is 1000 cycles. */
|
||||||
|
NULL,
|
||||||
|
{
|
||||||
|
{PWM_MCK_DIV_1 | PWM_OUTPUT_ACTIVE_HIGH | PWM_OUTPUT_PIN1 | PWM_DISABLEPULLUP_PIN1, NULL},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool_t pwmRunning = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise the board for the display.
|
* @brief Initialise the board for the display.
|
||||||
|
@ -99,6 +119,10 @@ static __inline void init_board(void) {
|
||||||
|
|
||||||
//pSPI->SPI_CSR[0] = 0x01010C11; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/32*12 = 125kHz
|
//pSPI->SPI_CSR[0] = 0x01010C11; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/32*12 = 125kHz
|
||||||
pSPI->SPI_CSR[0] = 0x01010311; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/8 = 6MHz if using commented MR line above
|
pSPI->SPI_CSR[0] = 0x01010311; //9bit, CPOL=1, ClockPhase=0, SCLK = 48Mhz/8 = 6MHz if using commented MR line above
|
||||||
|
|
||||||
|
/* Display backlight control at 100% */
|
||||||
|
pwmRunning = FALSE;
|
||||||
|
palSetPad(IOPORT2, PIOB_LCD_BL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,10 +150,28 @@ static __inline void setpin_reset(bool_t state) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
static __inline void set_backlight(uint8_t percent) {
|
static __inline void set_backlight(uint8_t percent) {
|
||||||
if (percent)
|
if (percent == 100) {
|
||||||
|
/* Turn the pin on - No PWM */
|
||||||
|
if (pwmRunning) {
|
||||||
|
pwmStop(&PWMD2);
|
||||||
|
pwmRunning = FALSE;
|
||||||
|
}
|
||||||
palSetPad(IOPORT2, PIOB_LCD_BL);
|
palSetPad(IOPORT2, PIOB_LCD_BL);
|
||||||
else
|
} else if (percent == 0) {
|
||||||
|
/* Turn the pin off - No PWM */
|
||||||
|
if (pwmRunning) {
|
||||||
|
pwmStop(&PWMD2);
|
||||||
|
pwmRunning = FALSE;
|
||||||
|
}
|
||||||
palClearPad(IOPORT2, PIOB_LCD_BL);
|
palClearPad(IOPORT2, PIOB_LCD_BL);
|
||||||
|
} else {
|
||||||
|
/* Use the PWM */
|
||||||
|
if (!pwmRunning) {
|
||||||
|
pwmStart(&PWMD2, &pwmcfg);
|
||||||
|
pwmRunning = TRUE;
|
||||||
|
}
|
||||||
|
pwmEnableChannel(&PWMD2, 0, PWM_VALUE(percent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue