diff options
| author | Bernard Xiong <[email protected]> | 2021-05-28 16:20:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-28 16:20:08 +0800 |
| commit | 92beddf3bccf6346e26aa097f82464456fb8e6bd (patch) | |
| tree | 197e4a108118dda016ea02274172f0c40e7ee8ed /bsp/mini2440/drivers | |
| parent | b18a99b44240ec3152011e159cc24a5af8dff0ce (diff) | |
| parent | 03f4d40e30f3c94e1db0b3a65b3610dee695694a (diff) | |
Merge pull request #4737 from mysterywolf/3,1,xformatv3.1.5
[lts 3.1.x] format codes
Diffstat (limited to 'bsp/mini2440/drivers')
| -rw-r--r-- | bsp/mini2440/drivers/board.c | 174 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/key.c | 454 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/lcd_a70.c | 242 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/lcd_n35.c | 234 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/lcd_t35.c | 242 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/lcd_x35.c | 238 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/led.c | 10 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/sdcard.c | 8 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/touch.c | 704 |
9 files changed, 1153 insertions, 1153 deletions
diff --git a/bsp/mini2440/drivers/board.c b/bsp/mini2440/drivers/board.c index a8592610aa..8029a7c507 100644 --- a/bsp/mini2440/drivers/board.c +++ b/bsp/mini2440/drivers/board.c @@ -8,7 +8,7 @@ * 2006-03-24 Bernard first implementation * 2006-05-05 Bernard add DATA_COUNT definition * 2006-10-05 Alsor.Z for s3c2410x porting - * 2007-11-20 Yi.Qiu add lcd,touch,console + * 2007-11-20 Yi.Qiu add lcd,touch,console */ #include <rtthread.h> @@ -31,23 +31,23 @@ extern void rt_hw_get_clock(void); extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn); extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv); -#define UART0 ((struct uartport *)&U0BASE) +#define UART0 ((struct uartport *)&U0BASE) struct serial_int_rx uart0_int_rx; struct serial_device uart0 = { - UART0, - &uart0_int_rx, - RT_NULL + UART0, + &uart0_int_rx, + RT_NULL }; struct rt_device uart0_device; -#define UART2 ((struct uartport *)&U2BASE) +#define UART2 ((struct uartport *)&U2BASE) struct serial_int_rx uart2_int_rx; struct serial_device uart2 = { - UART2, - &uart2_int_rx, - RT_NULL + UART2, + &uart2_int_rx, + RT_NULL }; struct rt_device uart2_device; @@ -56,7 +56,7 @@ struct rt_device uart2_device; */ static void rt_timer_handler(int vector, void *param) { - rt_tick_increase(); + rt_tick_increase(); } /** @@ -64,14 +64,14 @@ static void rt_timer_handler(int vector, void *param) */ static void rt_serial0_handler(int vector, void *param) { - INTSUBMSK |= (BIT_SUB_RXD0); + INTSUBMSK |= (BIT_SUB_RXD0); - rt_hw_serial_isr(&uart0_device); + rt_hw_serial_isr(&uart0_device); - SUBSRCPND |= BIT_SUB_RXD0; + SUBSRCPND |= BIT_SUB_RXD0; - /* Unmask sub interrupt (RXD0) */ - INTSUBMSK &=~(BIT_SUB_RXD0); + /* Unmask sub interrupt (RXD0) */ + INTSUBMSK &=~(BIT_SUB_RXD0); } /** @@ -79,14 +79,14 @@ static void rt_serial0_handler(int vector, void *param) */ static void rt_serial2_handler(int vector, void *param) { - INTSUBMSK |= (BIT_SUB_RXD2); + INTSUBMSK |= (BIT_SUB_RXD2); - rt_hw_serial_isr(&uart2_device); + rt_hw_serial_isr(&uart2_device); - SUBSRCPND |= BIT_SUB_RXD2; + SUBSRCPND |= BIT_SUB_RXD2; - /* Unmask sub interrupt (RXD0) */ - INTSUBMSK &=~(BIT_SUB_RXD2); + /* Unmask sub interrupt (RXD0) */ + INTSUBMSK &=~(BIT_SUB_RXD2); } /** @@ -94,55 +94,55 @@ static void rt_serial2_handler(int vector, void *param) */ static void rt_hw_uart_init(void) { - int i; - /* UART0 port configure */ - GPHCON |= 0xAA; - /* PULLUP is disable */ - GPHUP |= 0xF; + int i; + /* UART0 port configure */ + GPHCON |= 0xAA; + /* PULLUP is disable */ + GPHUP |= 0xF; - /* FIFO enable, Tx/Rx FIFO clear */ - uart0.uart_device->ufcon = 0x0; - /* disable the flow control */ - uart0.uart_device->umcon = 0x0; - /* Normal,No parity,1 stop,8 bit */ - uart0.uart_device->ulcon = 0x3; - /* - * tx=level,rx=edge,disable timeout int.,enable rx error int., - * normal,interrupt or polling - */ - uart0.uart_device->ucon = 0x245; - /* Set uart0 bps */ - uart0.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; - /* output PCLK to UART0/1, PWMTIMER */ - CLKCON |= 0x0D00; + /* FIFO enable, Tx/Rx FIFO clear */ + uart0.uart_device->ufcon = 0x0; + /* disable the flow control */ + uart0.uart_device->umcon = 0x0; + /* Normal,No parity,1 stop,8 bit */ + uart0.uart_device->ulcon = 0x3; + /* + * tx=level,rx=edge,disable timeout int.,enable rx error int., + * normal,interrupt or polling + */ + uart0.uart_device->ucon = 0x245; + /* Set uart0 bps */ + uart0.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; + /* output PCLK to UART0/1, PWMTIMER */ + CLKCON |= 0x0D00; - /* FIFO enable, Tx/Rx FIFO clear */ - uart2.uart_device->ufcon = 0x0; - /* disable the flow control */ - uart2.uart_device->umcon = 0x0; - /* Normal,No parity,1 stop,8 bit */ - uart2.uart_device->ulcon = 0x3; - /* - * tx=level,rx=edge,disable timeout int.,enable rx error int., - * normal,interrupt or polling - */ - uart2.uart_device->ucon = 0x245; - /* Set uart0 bps */ - uart2.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; + /* FIFO enable, Tx/Rx FIFO clear */ + uart2.uart_device->ufcon = 0x0; + /* disable the flow control */ + uart2.uart_device->umcon = 0x0; + /* Normal,No parity,1 stop,8 bit */ + uart2.uart_device->ulcon = 0x3; + /* + * tx=level,rx=edge,disable timeout int.,enable rx error int., + * normal,interrupt or polling + */ + uart2.uart_device->ucon = 0x245; + /* Set uart0 bps */ + uart2.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; - for (i = 0; i < 100; i++); + for (i = 0; i < 100; i++); - /* install uart0 isr */ - INTSUBMSK &= ~(BIT_SUB_RXD0); + /* install uart0 isr */ + INTSUBMSK &= ~(BIT_SUB_RXD0); - /* install uart2 isr */ - INTSUBMSK &= ~(BIT_SUB_RXD2); + /* install uart2 isr */ + INTSUBMSK &= ~(BIT_SUB_RXD2); - rt_hw_interrupt_install(INTUART0, rt_serial0_handler, RT_NULL, "UART0"); - rt_hw_interrupt_umask(INTUART0); + rt_hw_interrupt_install(INTUART0, rt_serial0_handler, RT_NULL, "UART0"); + rt_hw_interrupt_umask(INTUART0); - rt_hw_interrupt_install(INTUART2, rt_serial2_handler, RT_NULL, "UART2"); - rt_hw_interrupt_umask(INTUART2); + rt_hw_interrupt_install(INTUART2, rt_serial2_handler, RT_NULL, "UART2"); + rt_hw_interrupt_umask(INTUART2); } /** @@ -150,22 +150,22 @@ static void rt_hw_uart_init(void) */ static void rt_hw_timer_init(void) { - /* timer4, pre = 15+1 */ - TCFG0 &= 0xffff00ff; - TCFG0 |= 15 << 8; - /* all are interrupt mode,set Timer 4 MUX 1/4 */ - TCFG1 &= 0xfff0ffff; - TCFG1 |= 0x00010000; + /* timer4, pre = 15+1 */ + TCFG0 &= 0xffff00ff; + TCFG0 |= 15 << 8; + /* all are interrupt mode,set Timer 4 MUX 1/4 */ + TCFG1 &= 0xfff0ffff; + TCFG1 |= 0x00010000; - TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1; - /* manual update */ - TCON = TCON & (~(0x0f<<20)) | (0x02<<20); - /* install interrupt handler */ - rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL, "tick"); - rt_hw_interrupt_umask(INTTIMER4); + TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1; + /* manual update */ + TCON = TCON & (~(0x0f<<20)) | (0x02<<20); + /* install interrupt handler */ + rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL, "tick"); + rt_hw_interrupt_umask(INTTIMER4); /* start timer4, reload */ - TCON = TCON & (~(0x0f<<20)) | (0x05<<20); + TCON = TCON & (~(0x0f<<20)) | (0x05<<20); } /** @@ -173,23 +173,23 @@ static void rt_hw_timer_init(void) */ void rt_hw_board_init(void) { - /* initialize the system clock */ - rt_hw_clock_init(); + /* initialize the system clock */ + rt_hw_clock_init(); - /* Get the clock */ - rt_hw_get_clock(); + /* Get the clock */ + rt_hw_get_clock(); - /* initialize led port */ - rt_hw_led_init(); + /* initialize led port */ + rt_hw_led_init(); - /* initialize uart */ - rt_hw_uart_init(); + /* initialize uart */ + rt_hw_uart_init(); - /* initialize mmu */ - rt_hw_mmu_init(); + /* initialize mmu */ + rt_hw_mmu_init(); - /* initialize timer4 */ - rt_hw_timer_init(); + /* initialize timer4 */ + rt_hw_timer_init(); } /*@}*/ diff --git a/bsp/mini2440/drivers/key.c b/bsp/mini2440/drivers/key.c index 8c59b0fbdf..c33285c290 100644 --- a/bsp/mini2440/drivers/key.c +++ b/bsp/mini2440/drivers/key.c @@ -8,68 +8,68 @@ * 2010-10-01 Yi.Qiu first version */ - /* - * Warning, this keypad driver can only work on QEMU emulator + /* + * Warning, this keypad driver can only work on QEMU emulator */ - + #include <rtthread.h> #include <s3c24x0.h> #include <rthw.h> -#define KEY_RX_BUFFER_SIZE 32 +#define KEY_RX_BUFFER_SIZE 32 struct rt_key_device { - struct rt_device parent; + struct rt_device parent; - rt_uint32_t rx_buffer[KEY_RX_BUFFER_SIZE]; - rt_uint32_t read_index, save_index; -}; + rt_uint32_t rx_buffer[KEY_RX_BUFFER_SIZE]; + rt_uint32_t read_index, save_index; +}; static struct rt_key_device *key_device = RT_NULL; /* save a char to serial buffer */ static void rt_key_savechar(char ch) { - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); + rt_base_t level; + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); - key_device->rx_buffer[key_device->save_index] = ch; - key_device->save_index ++; - if (key_device->save_index >= KEY_RX_BUFFER_SIZE) - key_device->save_index = 0; - - /* if the next position is read index, discard this 'read char' */ - if (key_device->save_index == key_device->read_index) - { - key_device->read_index ++; - if (key_device->read_index >= KEY_RX_BUFFER_SIZE) - key_device->read_index = 0; - } + key_device->rx_buffer[key_device->save_index] = ch; + key_device->save_index ++; + if (key_device->save_index >= KEY_RX_BUFFER_SIZE) + key_device->save_index = 0; - /* enable interrupt */ - rt_hw_interrupt_enable(level); + /* if the next position is read index, discard this 'read char' */ + if (key_device->save_index == key_device->read_index) + { + key_device->read_index ++; + if (key_device->read_index >= KEY_RX_BUFFER_SIZE) + key_device->read_index = 0; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); } /* ISR for serial interrupt */ static void rt_hw_key_isr(void) { - /* save on rx buffer */ - rt_key_savechar(URXH1 & 0xff); + /* save on rx buffer */ + rt_key_savechar(URXH1 & 0xff); + + /* invoke callback */ + if (key_device->parent.rx_indicate != RT_NULL) + { + rt_size_t rx_length; - /* invoke callback */ - if (key_device->parent.rx_indicate != RT_NULL) - { - rt_size_t rx_length; - - /* get rx length */ - rx_length = key_device->read_index > key_device->save_index ? - KEY_RX_BUFFER_SIZE - key_device->read_index + key_device->save_index : - key_device->save_index - key_device->read_index; + /* get rx length */ + rx_length = key_device->read_index > key_device->save_index ? + KEY_RX_BUFFER_SIZE - key_device->read_index + key_device->save_index : + key_device->save_index - key_device->read_index; - key_device->parent.rx_indicate(&key_device->parent, rx_length); - } + key_device->parent.rx_indicate(&key_device->parent, rx_length); + } } /** @@ -77,14 +77,14 @@ static void rt_hw_key_isr(void) */ static void rt_key_handler(int vector) { - INTSUBMSK |= (BIT_SUB_RXD1); + INTSUBMSK |= (BIT_SUB_RXD1); - rt_hw_key_isr(); - - SUBSRCPND |= BIT_SUB_RXD1; - - /*Unmask sub interrupt (RXD0)*/ - INTSUBMSK &=~(BIT_SUB_RXD1); + rt_hw_key_isr(); + + SUBSRCPND |= BIT_SUB_RXD1; + + /*Unmask sub interrupt (RXD0)*/ + INTSUBMSK &=~(BIT_SUB_RXD1); } /** @@ -92,114 +92,114 @@ static void rt_key_handler(int vector) */ static void key_init(void) { - int i = 0; + int i = 0; + + GPHCON |= 0xa0; + /*PULLUP is enable */ + GPHUP |= 0x0c; - GPHCON |= 0xa0; - /*PULLUP is enable */ - GPHUP |= 0x0c; - - /* FIFO enable, Tx/Rx FIFO clear */ - UFCON1 = 0x0; - /* disable the flow control */ - UMCON1= 0x0; - /* Normal,No parity,1 stop,8 bit */ - ULCON1 = 0x3; - /* - * tx=level,rx=edge,disable timeout int.,enable rx error int., - * normal,interrupt or polling - */ - UCON1 = 0x245; + /* FIFO enable, Tx/Rx FIFO clear */ + UFCON1 = 0x0; + /* disable the flow control */ + UMCON1= 0x0; + /* Normal,No parity,1 stop,8 bit */ + ULCON1 = 0x3; + /* + * tx=level,rx=edge,disable timeout int.,enable rx error int., + * normal,interrupt or polling + */ + UCON1 = 0x245; - //UBRD0 = div; - // UBRD0 = 0x500; /* baudrate = 19200bps */ - UBRD1 = 0x1a; + //UBRD0 = div; + // UBRD0 = 0x500; /* baudrate = 19200bps */ + UBRD1 = 0x1a; - UTXH1 = 0x2; - URXH1 = 0x1; + UTXH1 = 0x2; + URXH1 = 0x1; - /* output PCLK to UART0/1, PWMTIMER */ - CLKCON |= 0x0D00; + /* output PCLK to UART0/1, PWMTIMER */ + CLKCON |= 0x0D00; - for (i = 0; i < 100; i++); + for (i = 0; i < 100; i++); - /* install key isr */ - INTSUBMSK &= ~(BIT_SUB_RXD1); + /* install key isr */ + INTSUBMSK &= ~(BIT_SUB_RXD1); - rt_hw_interrupt_install(INTUART1, rt_key_handler, RT_NULL , "INTUART1"); - rt_hw_interrupt_umask(INTUART1); + rt_hw_interrupt_install(INTUART1, rt_key_handler, RT_NULL , "INTUART1"); + rt_hw_interrupt_umask(INTUART1); } static rt_err_t rt_key_init(rt_device_t dev) -{ - if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) - { +{ + if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) + { - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - rt_memset(key_device->rx_buffer, 0, - sizeof(key_device->rx_buffer)); - key_device->read_index = key_device->save_index = 0; - } + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + rt_memset(key_device->rx_buffer, 0, + sizeof(key_device->rx_buffer)); + key_device->read_index = key_device->save_index = 0; + } - dev->flag |= RT_DEVICE_FLAG_ACTIVATED; - } + dev->flag |= RT_DEVICE_FLAG_ACTIVATED; + } - return RT_EOK; + return RT_EOK; } static rt_err_t rt_key_open(rt_device_t dev, rt_uint16_t oflag) -{ - return RT_EOK; +{ + return RT_EOK; } static rt_err_t rt_key_close(rt_device_t dev) -{ - return RT_EOK; +{ + return RT_EOK; } static rt_size_t rt_key_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { - rt_uint8_t* ptr; - rt_err_t err_code; - rt_base_t level; - - ptr = buffer; - err_code = RT_EOK; + rt_uint8_t* ptr; + rt_err_t err_code; + rt_base_t level; + + ptr = buffer; + err_code = RT_EOK; - /* interrupt mode Rx */ - while (size) - { - if (key_device->read_index != key_device->save_index) - { - *ptr++ = key_device->rx_buffer[key_device->read_index]; - size --; + /* interrupt mode Rx */ + while (size) + { + if (key_device->read_index != key_device->save_index) + { + *ptr++ = key_device->rx_buffer[key_device->read_index]; + size --; - /* disable interrupt */ - level = rt_hw_interrupt_disable(); + /* disable interrupt */ + level = rt_hw_interrupt_disable(); - key_device->read_index ++; - if (key_device->read_index >= KEY_RX_BUFFER_SIZE) - key_device->read_index = 0; + key_device->read_index ++; + if (key_device->read_index >= KEY_RX_BUFFER_SIZE) + key_device->read_index = 0; - /* enable interrupt */ - rt_hw_interrupt_enable(level); - } - else - { - /* set error code */ - err_code = -RT_EEMPTY; - break; - } - } + /* enable interrupt */ + rt_hw_interrupt_enable(level); + } + else + { + /* set error code */ + err_code = -RT_EEMPTY; + break; + } + } - /* set error code */ - rt_set_errno(err_code); - return (rt_uint32_t)ptr - (rt_uint32_t)buffer; + /* set error code */ + rt_set_errno(err_code); + return (rt_uint32_t)ptr - (rt_uint32_t)buffer; } static rt_err_t rt_key_control(rt_device_t dev, int cmd, void *args) { - return RT_EOK; + return RT_EOK; } #ifdef RT_USING_RTGUI @@ -211,96 +211,96 @@ static int s_key_map[0xff] = {0}; static void rt_keymap_init(void) { - s_key_map[0x1] = RTGUIK_ESCAPE; - s_key_map[0xc] = RTGUIK_MINUS; - s_key_map[0x39] = RTGUIK_SPACE; - s_key_map[0xd] = RTGUIK_KP_EQUALS; - s_key_map[0xe] = RTGUIK_BACKSPACE; - s_key_map[0xf] = RTGUIK_TAB; - s_key_map[0x1c] = RTGUIK_KP_ENTER; - s_key_map[0xb] = RTGUIK_0; - s_key_map[0x2] = RTGUIK_1; - s_key_map[0x3] = RTGUIK_2; - s_key_map[0x4] = RTGUIK_3; - s_key_map[0x5] = RTGUIK_4; - s_key_map[0x6] = RTGUIK_5; - s_key_map[0x7] = RTGUIK_6; - s_key_map[0x8] = RTGUIK_7; - s_key_map[0x9] = RTGUIK_8; - s_key_map[0xa] = RTGUIK_9; - s_key_map[0x3b] = RTGUIK_F1; - s_key_map[0x3c] = RTGUIK_F2; - s_key_map[0x3d] = RTGUIK_F3; - s_key_map[0x3e] = RTGUIK_F4; - s_key_map[0xef] = RTGUIK_F5; - s_key_map[0x40] = RTGUIK_F6; - s_key_map[0x41] = RTGUIK_F7; - s_key_map[0x42] = RTGUIK_F8; - s_key_map[0x43] = RTGUIK_F9; - s_key_map[0x1e] = RTGUIK_a; - s_key_map[0x30] = RTGUIK_b; - s_key_map[0x2c] = RTGUIK_c; - s_key_map[0x20] = RTGUIK_d; - s_key_map[0x12] = RTGUIK_e; - s_key_map[0x21] = RTGUIK_f; - s_key_map[0x22] = RTGUIK_g; - s_key_map[0x23] = RTGUIK_h; - s_key_map[0x17] = RTGUIK_i; - s_key_map[0x24] = RTGUIK_j; - s_key_map[0x25] = RTGUIK_k; - s_key_map[0x26] = RTGUIK_l; - s_key_map[0x32] = RTGUIK_m; - s_key_map[0x31] = RTGUIK_n; - s_key_map[0x18] = RTGUIK_o; - s_key_map[0x19] = RTGUIK_p; - s_key_map[0x10] = RTGUIK_q; - s_key_map[0x13] = RTGUIK_r; - s_key_map[0x1f] = RTGUIK_s; - s_key_map[0x14] = RTGUIK_t; - s_key_map[0x16] = RTGUIK_u; - s_key_map[0x2f] = RTGUIK_v; - s_key_map[0x11] = RTGUIK_w; - s_key_map[0x2d] = RTGUIK_x; - s_key_map[0x15] = RTGUIK_y; - s_key_map[0x2c] = RTGUIK_z; - s_key_map[0x4b] = RTGUIK_LEFT; - s_key_map[0x4d] = RTGUIK_RIGHT; - s_key_map[0x50] = RTGUIK_DOWN; - s_key_map[0x2e] = RTGUIK_DELETE; - s_key_map[0x48] = RTGUIK_UP; -} + s_key_map[0x1] = RTGUIK_ESCAPE; + s_key_map[0xc] = RTGUIK_MINUS; + s_key_map[0x39] = RTGUIK_SPACE; + s_key_map[0xd] = RTGUIK_KP_EQUALS; + s_key_map[0xe] = RTGUIK_BACKSPACE; + s_key_map[0xf] = RTGUIK_TAB; + s_key_map[0x1c] = RTGUIK_KP_ENTER; + s_key_map[0xb] = RTGUIK_0; + s_key_map[0x2] = RTGUIK_1; + s_key_map[0x3] = RTGUIK_2; + s_key_map[0x4] = RTGUIK_3; + s_key_map[0x5] = RTGUIK_4; + s_key_map[0x6] = RTGUIK_5; + s_key_map[0x7] = RTGUIK_6; + s_key_map[0x8] = RTGUIK_7; + s_key_map[0x9] = RTGUIK_8; + s_key_map[0xa] = RTGUIK_9; + s_key_map[0x3b] = RTGUIK_F1; + s_key_map[0x3c] = RTGUIK_F2; + s_key_map[0x3d] = RTGUIK_F3; + s_key_map[0x3e] = RTGUIK_F4; + s_key_map[0xef] = RTGUIK_F5; + s_key_map[0x40] = RTGUIK_F6; + s_key_map[0x41] = RTGUIK_F7; + s_key_map[0x42] = RTGUIK_F8; + s_key_map[0x43] = RTGUIK_F9; + s_key_map[0x1e] = RTGUIK_a; + s_key_map[0x30] = RTGUIK_b; + s_key_map[0x2c] = RTGUIK_c; + s_key_map[0x20] = RTGUIK_d; + s_key_map[0x12] = RTGUIK_e; + s_key_map[0x21] = RTGUIK_f; + s_key_map[0x22] = RTGUIK_g; + s_key_map[0x23] = RTGUIK_h; + s_key_map[0x17] = RTGUIK_i; + s_key_map[0x24] = RTGUIK_j; + s_key_map[0x25] = RTGUIK_k; + s_key_map[0x26] = RTGUIK_l; + s_key_map[0x32] = RTGUIK_m; + s_key_map[0x31] = RTGUIK_n; + s_key_map[0x18] = RTGUIK_o; + s_key_map[0x19] = RTGUIK_p; + s_key_map[0x10] = RTGUIK_q; + s_key_map[0x13] = RTGUIK_r; + s_key_map[0x1f] = RTGUIK_s; + s_key_map[0x14] = RTGUIK_t; + s_key_map[0x16] = RTGUIK_u; + s_key_map[0x2f] = RTGUIK_v; + s_key_map[0x11] = RTGUIK_w; + s_key_map[0x2d] = RTGUIK_x; + s_key_map[0x15] = RTGUIK_y; + s_key_map[0x2c] = RTGUIK_z; + s_key_map[0x4b] = RTGUIK_LEFT; + s_key_map[0x4d] = RTGUIK_RIGHT; + s_key_map[0x50] = RTGUIK_DOWN; + s_key_map[0x2e] = RTGUIK_DELETE; + s_key_map[0x48] = RTGUIK_UP; +} static rt_err_t rtgui_key_rx(rt_device_t dev, rt_size_t size) { - struct rtgui_event_kbd kbd_event; - char key_value; + struct rtgui_event_kbd kbd_event; + char key_value; + + while(rt_device_read(dev, 0, &key_value, 1) == 1) + { + /* init keyboard event */ + RTGUI_EVENT_KBD_INIT(&kbd_event); + kbd_event.mod = RTGUI_KMOD_NONE; + kbd_event.unicode = 0; + kbd_event.key = RTGUIK_UNKNOWN; - while(rt_device_read(dev, 0, &key_value, 1) == 1) - { - /* init keyboard event */ - RTGUI_EVENT_KBD_INIT(&kbd_event); - kbd_event.mod = RTGUI_KMOD_NONE; - kbd_event.unicode = 0; - kbd_event.key = RTGUIK_UNKNOWN; + if(key_value & 0x80) + { + kbd_event.type = RTGUI_KEYUP; + } + else + { + kbd_event.type = RTGUI_KEYDOWN; + } - if(key_value & 0x80) - { - kbd_event.type = RTGUI_KEYUP; - } - else - { - kbd_event.type = RTGUI_KEYDOWN; - } + kbd_event.key = s_key_map[key_value & 0x7F]; + } + if (kbd_event.key != RTGUIK_UNKNOWN) + { + /* post down event */ + rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); + } - kbd_event.key = s_key_map[key_value & 0x7F]; - } - if (kbd_event.key != RTGUIK_UNKNOWN) - { - /* post down event */ - rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); - } - - return RT_EOK; + return RT_EOK; } #endif @@ -310,33 +310,33 @@ static rt_err_t rtgui_key_rx(rt_device_t dev, rt_size_t size) */ void rt_hw_key_init(void) { - /* hardware init */ - key_init(); + /* hardware init */ + key_init(); + + key_device = (struct rt_key_device*)rt_malloc (sizeof(struct rt_key_device)); + if (key_device == RT_NULL) return; /* no memory yet */ - key_device = (struct rt_key_device*)rt_malloc (sizeof(struct rt_key_device)); - if (key_device == RT_NULL) return; /* no memory yet */ + /* clear device structure */ + rt_memset(&(key_device->parent), 0, sizeof(struct rt_device)); - /* clear device structure */ - rt_memset(&(key_device->parent), 0, sizeof(struct rt_device)); - - key_device->parent.type = RT_Device_Class_Char; - key_device->parent.tx_complete = RT_NULL; - key_device->parent.init = rt_key_init; - key_device->parent.open = rt_key_open; - key_device->parent.close = rt_key_close; - key_device->parent.read = rt_key_read; - key_device->parent.write = RT_NULL; - key_device->parent.control = rt_key_control; - key_device->parent.user_data = RT_NULL; + key_device->parent.type = RT_Device_Class_Char; + key_device->parent.tx_complete = RT_NULL; + key_device->parent.init = rt_key_init; + key_device->parent.open = rt_key_open; + key_device->parent.close = rt_key_close; + key_device->parent.read = rt_key_read; + key_device->parent.write = RT_NULL; + key_device->parent.control = rt_key_control; + key_device->parent.user_data = RT_NULL; #ifdef RT_USING_RTGUI - key_device->parent.rx_indicate = rtgui_key_rx; + key_device->parent.rx_indicate = rtgui_key_rx; - /* init keymap */ - rt_keymap_init(); + /* init keymap */ + rt_keymap_init(); #endif - /* register key device to RT-Thread */ - rt_device_register(&(key_device->parent), "key", RT_DEVICE_FLAG_RDONLY | RT_DEVICE_FLAG_INT_RX); + /* register key device to RT-Thread */ + rt_device_register(&(key_device->parent), "key", RT_DEVICE_FLAG_RDONLY | RT_DEVICE_FLAG_INT_RX); } diff --git a/bsp/mini2440/drivers/lcd_a70.c b/bsp/mini2440/drivers/lcd_a70.c index 4ce787cbcc..a6b92f69e5 100644 --- a/bsp/mini2440/drivers/lcd_a70.c +++ b/bsp/mini2440/drivers/lcd_a70.c @@ -31,81 +31,81 @@ #define SCR_XSIZE LCD_WIDTH #define SCR_YSIZE LCD_HEIGHT -#define RT_HW_LCD_WIDTH LCD_WIDTH -#define RT_HW_LCD_HEIGHT LCD_HEIGHT +#define RT_HW_LCD_WIDTH LCD_WIDTH +#define RT_HW_LCD_HEIGHT LCD_HEIGHT -#define MVAL (13) -#define MVAL_USED (0) //0=each frame 1=rate by MVAL -#define INVVDEN (1) //0=normal 1=inverted -#define BSWP (0) //Byte swap control -#define HWSWP (1) //Half word swap control +#define MVAL (13) +#define MVAL_USED (0) //0=each frame 1=rate by MVAL +#define INVVDEN (1) //0=normal 1=inverted +#define BSWP (0) //Byte swap control +#define HWSWP (1) //Half word swap control -#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) -#define GPB1_TO_1() (GPBDAT |= 0x0002) -#define GPB1_TO_0() (GPBDAT &= 0xfffd) +#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) +#define GPB1_TO_1() (GPBDAT |= 0x0002) +#define GPB1_TO_0() (GPBDAT &= 0xfffd) #define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8) -#define S3C2410_LCDCON1_MMODE (1<<7) -#define S3C2410_LCDCON1_DSCAN4 (0<<5) -#define S3C2410_LCDCON1_STN4 (1<<5) -#define S3C2410_LCDCON1_STN8 (2<<5) -#define S3C2410_LCDCON1_TFT (3<<5) +#define S3C2410_LCDCON1_MMODE (1<<7) +#define S3C2410_LCDCON1_DSCAN4 (0<<5) +#define S3C2410_LCDCON1_STN4 (1<<5) +#define S3C2410_LCDCON1_STN8 (2<<5) +#define S3C2410_LCDCON1_TFT (3<<5) -#define S3C2410_LCDCON1_STN1BPP (0<<1) +#define S3C2410_LCDCON1_STN1BPP (0<<1) #define S3C2410_LCDCON1_STN2GREY (1<<1) #define S3C2410_LCDCON1_STN4GREY (2<<1) -#define S3C2410_LCDCON1_STN8BPP (3<<1) +#define S3C2410_LCDCON1_STN8BPP (3<<1) #define S3C2410_LCDCON1_STN12BPP (4<<1) -#define S3C2410_LCDCON1_TFT1BPP (8<<1) -#define S3C2410_LCDCON1_TFT2BPP (9<<1) -#define S3C2410_LCDCON1_TFT4BPP (10<<1) -#define S3C2410_LCDCON1_TFT8BPP (11<<1) +#define S3C2410_LCDCON1_TFT1BPP (8<<1) +#define S3C2410_LCDCON1_TFT2BPP (9<<1) +#define S3C2410_LCDCON1_TFT4BPP (10<<1) +#define S3C2410_LCDCON1_TFT8BPP (11<<1) #define S3C2410_LCDCON1_TFT16BPP (12<<1) #define S3C2410_LCDCON1_TFT24BPP (13<<1) -#define S3C2410_LCDCON1_ENVID (1) +#define S3C2410_LCDCON1_ENVID (1) #define S3C2410_LCDCON1_MODEMASK 0x1E -#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) +#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) #define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14) -#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) -#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) +#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) +#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) #define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF) #define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF) #define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F) -#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) -#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) +#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) +#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) #define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8) -#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) +#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) #define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0) #define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F) #define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) -#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) -#define S3C2410_LCDCON4_WLH(x) ((x) << 0) +#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) +#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) +#define S3C2410_LCDCON4_WLH(x) ((x) << 0) #define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON5_BPP24BL (1<<12) -#define S3C2410_LCDCON5_FRM565 (1<<11) -#define S3C2410_LCDCON5_INVVCLK (1<<10) +#define S3C2410_LCDCON5_BPP24BL (1<<12) +#define S3C2410_LCDCON5_FRM565 (1<<11) +#define S3C2410_LCDCON5_INVVCLK (1<<10) #define S3C2410_LCDCON5_INVVLINE (1<<9) #define S3C2410_LCDCON5_INVVFRAME (1<<8) -#define S3C2410_LCDCON5_INVVD (1<<7) -#define S3C2410_LCDCON5_INVVDEN (1<<6) +#define S3C2410_LCDCON5_INVVD (1<<7) +#define S3C2410_LCDCON5_INVVDEN (1<<6) #define S3C2410_LCDCON5_INVPWREN (1<<5) -#define S3C2410_LCDCON5_INVLEND (1<<4) -#define S3C2410_LCDCON5_PWREN (1<<3) -#define S3C2410_LCDCON5_ENLEND (1<<2) -#define S3C2410_LCDCON5_BSWP (1<<1) -#define S3C2410_LCDCON5_HWSWP (1<<0) -#define S3C2410_LCDINT_FRSYNC (1<<1) +#define S3C2410_LCDCON5_INVLEND (1<<4) +#define S3C2410_LCDCON5_PWREN (1<<3) +#define S3C2410_LCDCON5_ENLEND (1<<2) +#define S3C2410_LCDCON5_BSWP (1<<1) +#define S3C2410_LCDCON5_HWSWP (1<<0) +#define S3C2410_LCDINT_FRSYNC (1<<1) static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; //static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; @@ -124,121 +124,121 @@ static void lcd_power_enable(int invpwren, int pwren) static void lcd_envid_on_off(int onoff) { - if(onoff==1) - /*ENVID=ON*/ - LCDCON1|=1; - else - /*ENVID Off*/ - LCDCON1 =LCDCON1 & 0x3fffe; + if(onoff==1) + /*ENVID=ON*/ + LCDCON1|=1; + else + /*ENVID Off*/ + LCDCON1 =LCDCON1 & 0x3fffe; } //********************** BOARD LCD backlight **************************** static void LcdBkLtSet(rt_uint32_t HiRatio) { -#define FREQ_PWM1 1000 - if(!HiRatio) - { - GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output - GPBDAT &= ~(1<<1); - return; - } - GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; +#define FREQ_PWM1 1000 + if(!HiRatio) + { + GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output + GPBDAT &= ~(1<<1); + return; + } + GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; - if( HiRatio > 100 ) HiRatio = 100 ; + if( HiRatio > 100 ) HiRatio = 100 ; - TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 + TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 - TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 - TCFG0 |= 15; //prescaler = 15+1 + TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 + TCFG0 |= 15; //prescaler = 15+1 - TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 - TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 + TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 + TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 - TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low - TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high + TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low + TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high - TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; - TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) -{ - GPB1_TO_OUT(); - GPB1_TO_1(); +{ + GPB1_TO_OUT(); + GPB1_TO_1(); - GPCUP = 0x00000000; - GPCCON = 0xaaaa02a9; + GPCUP = 0x00000000; + GPCCON = 0xaaaa02a9; - GPDUP = 0x00000000; - GPDCON = 0xaaaaaaaa; + GPDUP = 0x00000000; + GPDCON = 0xaaaaaaaa; -#define M5D(n) ((n)&0x1fffff) +#define M5D(n) ((n)&0x1fffff) #define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) - LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); - LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); - LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); - LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); + LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); + LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); + LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); + LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); #if !defined(LCD_CON5) #define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0)) #endif - LCDCON5 = LCD_CON5; + LCDCON5 = LCD_CON5; - LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0); - LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); - LCDSADDR3 = LCD_WIDTH; + LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0); + LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); + LCDSADDR3 = LCD_WIDTH; - LCDINTMSK |= (3); - LPCSEL &= (~7) ; - TPAL=0; + LCDINTMSK |= (3); + LPCSEL &= (~7) ; + TPAL=0; - LcdBkLtSet(70) ; - lcd_power_enable(0, 1); - lcd_envid_on_off(1); + LcdBkLtSet(70) ; + lcd_power_enable(0, 1); + lcd_envid_on_off(1); - return RT_EOK; + return RT_EOK; } static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_lcd_init(void) { - rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); + if (lcd == RT_NULL) return; /* no memory yet */ + + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; - _lcd_info.bits_per_pixel = 16; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; - _lcd_info.framebuffer = (void*)_rt_framebuffer; - _lcd_info.width = LCD_WIDTH; - _lcd_info.height = LCD_HEIGHT; + /* init device structure */ + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* init device structure */ - lcd->type = RT_Device_Class_Unknown; - lcd->init = rt_lcd_init; - lcd->open = RT_NULL; - lcd->close = RT_NULL; - lcd->control = rt_lcd_control; - lcd->user_data = (void*)&_lcd_info; - - /* register lcd device to RT-Thread */ - rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/drivers/lcd_n35.c b/bsp/mini2440/drivers/lcd_n35.c index 25881b0f14..5abf5f4f21 100644 --- a/bsp/mini2440/drivers/lcd_n35.c +++ b/bsp/mini2440/drivers/lcd_n35.c @@ -31,82 +31,82 @@ #define SCR_XSIZE LCD_WIDTH #define SCR_YSIZE LCD_HEIGHT -#define RT_HW_LCD_WIDTH LCD_WIDTH -#define RT_HW_LCD_HEIGHT LCD_HEIGHT +#define RT_HW_LCD_WIDTH LCD_WIDTH +#define RT_HW_LCD_HEIGHT LCD_HEIGHT -#define MVAL (13) -#define MVAL_USED (0) //0=each frame 1=rate by MVAL -#define INVVDEN (1) //0=normal 1=inverted -#define BSWP (0) //Byte swap control -#define HWSWP (1) //Half word swap control +#define MVAL (13) +#define MVAL_USED (0) //0=each frame 1=rate by MVAL +#define INVVDEN (1) //0=normal 1=inverted +#define BSWP (0) //Byte swap control +#define HWSWP (1) //Half word swap control -#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) -#define GPB1_TO_1() (GPBDAT |= 0x0002) -#define GPB1_TO_0() (GPBDAT &= 0xfffd) +#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) +#define GPB1_TO_1() (GPBDAT |= 0x0002) +#define GPB1_TO_0() (GPBDAT &= 0xfffd) #define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8) -#define S3C2410_LCDCON1_MMODE (1<<7) -#define S3C2410_LCDCON1_DSCAN4 (0<<5) -#define S3C2410_LCDCON1_STN4 (1<<5) -#define S3C2410_LCDCON1_STN8 (2<<5) -#define S3C2410_LCDCON1_TFT (3<<5) +#define S3C2410_LCDCON1_MMODE (1<<7) +#define S3C2410_LCDCON1_DSCAN4 (0<<5) +#define S3C2410_LCDCON1_STN4 (1<<5) +#define S3C2410_LCDCON1_STN8 (2<<5) +#define S3C2410_LCDCON1_TFT (3<<5) -#define S3C2410_LCDCON1_STN1BPP (0<<1) +#define S3C2410_LCDCON1_STN1BPP (0<<1) #define S3C2410_LCDCON1_STN2GREY (1<<1) #define S3C2410_LCDCON1_STN4GREY (2<<1) -#define S3C2410_LCDCON1_STN8BPP (3<<1) +#define S3C2410_LCDCON1_STN8BPP (3<<1) #define S3C2410_LCDCON1_STN12BPP (4<<1) -#define S3C2410_LCDCON1_TFT1BPP (8<<1) -#define S3C2410_LCDCON1_TFT2BPP (9<<1) -#define S3C2410_LCDCON1_TFT4BPP (10<<1) -#define S3C2410_LCDCON1_TFT8BPP (11<<1) +#define S3C2410_LCDCON1_TFT1BPP (8<<1) +#define S3C2410_LCDCON1_TFT2BPP (9<<1) +#define S3C2410_LCDCON1_TFT4BPP (10<<1) +#define S3C2410_LCDCON1_TFT8BPP (11<<1) #define S3C2410_LCDCON1_TFT16BPP (12<<1) #define S3C2410_LCDCON1_TFT24BPP (13<<1) -#define S3C2410_LCDCON1_ENVID (1) +#define S3C2410_LCDCON1_ENVID (1) #define S3C2410_LCDCON1_MODEMASK 0x1E -#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) +#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) #define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14) -#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) -#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) +#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) +#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) #define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF) #define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF) #define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F) -#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) -#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) +#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) +#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) #define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8) -#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) +#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) #define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0) #define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F) #define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) -#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) -#define S3C2410_LCDCON4_WLH(x) ((x) << 0) +#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) +#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) +#define S3C2410_LCDCON4_WLH(x) ((x) << 0) #define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON5_BPP24BL (1<<12) -#define S3C2410_LCDCON5_FRM565 (1<<11) -#define S3C2410_LCDCON5_INVVCLK (1<<10) +#define S3C2410_LCDCON5_BPP24BL (1<<12) +#define S3C2410_LCDCON5_FRM565 (1<<11) +#define S3C2410_LCDCON5_INVVCLK (1<<10) #define S3C2410_LCDCON5_INVVLINE (1<<9) #define S3C2410_LCDCON5_INVVFRAME (1<<8) -#define S3C2410_LCDCON5_INVVD (1<<7) -#define S3C2410_LCDCON5_INVVDEN (1<<6) +#define S3C2410_LCDCON5_INVVD (1<<7) +#define S3C2410_LCDCON5_INVVDEN (1<<6) #define S3C2410_LCDCON5_INVPWREN (1<<5) -#define S3C2410_LCDCON5_INVLEND (1<<4) -#define S3C2410_LCDCON5_PWREN (1<<3) -#define S3C2410_LCDCON5_ENLEND (1<<2) -#define S3C2410_LCDCON5_BSWP (1<<1) -#define S3C2410_LCDCON5_HWSWP (1<<0) +#define S3C2410_LCDCON5_INVLEND (1<<4) +#define S3C2410_LCDCON5_PWREN (1<<3) +#define S3C2410_LCDCON5_ENLEND (1<<2) +#define S3C2410_LCDCON5_BSWP (1<<1) +#define S3C2410_LCDCON5_HWSWP (1<<0) -#define S3C2410_LCDINT_FRSYNC (1<<1) +#define S3C2410_LCDINT_FRSYNC (1<<1) static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; //static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; @@ -125,61 +125,61 @@ static void lcd_power_enable(int invpwren, int pwren) static void lcd_envid_on_off(int onoff) { - if(onoff==1) - /*ENVID=ON*/ - LCDCON1|=1; - else - /*ENVID Off*/ - LCDCON1 =LCDCON1 & 0x3fffe; + if(onoff==1) + /*ENVID=ON*/ + LCDCON1|=1; + else + /*ENVID Off*/ + LCDCON1 =LCDCON1 & 0x3fffe; } //********************** BOARD LCD backlight **************************** static void LcdBkLtSet(rt_uint32_t HiRatio) { -#define FREQ_PWM1 1000 - if(!HiRatio) - { - GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output - GPBDAT &= ~(1<<1); - return; - } - GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; +#define FREQ_PWM1 1000 + if(!HiRatio) + { + GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output + GPBDAT &= ~(1<<1); + return; + } + GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; - if( HiRatio > 100 ) HiRatio = 100 ; + if( HiRatio > 100 ) HiRatio = 100 ; - TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 + TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 - TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 - TCFG0 |= 15; //prescaler = 15+1 + TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 + TCFG0 |= 15; //prescaler = 15+1 - TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 - TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 + TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 + TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 - TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low - TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high + TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low + TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high - TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; - TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) -{ - GPB1_TO_OUT(); - GPB1_TO_1(); +{ + GPB1_TO_OUT(); + GPB1_TO_1(); - GPCUP = 0x00000000; - GPCCON = 0xaaaa02a9; + GPCUP = 0x00000000; + GPCCON = 0xaaaa02a9; - GPDUP = 0x00000000; - GPDCON = 0xaaaaaaaa; + GPDUP = 0x00000000; + GPDCON = 0xaaaaaaaa; -#define M5D(n) ((n)&0x1fffff) +#define M5D(n) ((n)&0x1fffff) #define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) - LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); - LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); - LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); - LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); + LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); + LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); + LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); + LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); #if !defined(LCD_CON5) #define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0)) #endif @@ -189,57 +189,57 @@ static rt_err_t rt_lcd_init (rt_device_t dev) LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); LCDSADDR3 = LCD_WIDTH; - LCDINTMSK |= (3); - LPCSEL &= (~7) ; - TPAL=0; + LCDINTMSK |= (3); + LPCSEL &= (~7) ; + TPAL=0; - LcdBkLtSet(70) ; - lcd_power_enable(0, 1); - lcd_envid_on_off(1); + LcdBkLtSet(70) ; + lcd_power_enable(0, 1); + lcd_envid_on_off(1); - return RT_EOK; + return RT_EOK; } static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_lcd_init(void) { - rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); + if (lcd == RT_NULL) return; /* no memory yet */ + + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; - _lcd_info.bits_per_pixel = 16; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; - _lcd_info.framebuffer = (void*)_rt_framebuffer; - _lcd_info.width = LCD_WIDTH; - _lcd_info.height = LCD_HEIGHT; + /* init device structure */ + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* init device structure */ - lcd->type = RT_Device_Class_Unknown; - lcd->init = rt_lcd_init; - lcd->open = RT_NULL; - lcd->close = RT_NULL; - lcd->control = rt_lcd_control; - lcd->user_data = (void*)&_lcd_info; - - /* register lcd device to RT-Thread */ - rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/drivers/lcd_t35.c b/bsp/mini2440/drivers/lcd_t35.c index 51e038ec8b..5a19e3f68a 100644 --- a/bsp/mini2440/drivers/lcd_t35.c +++ b/bsp/mini2440/drivers/lcd_t35.c @@ -31,82 +31,82 @@ #define SCR_XSIZE LCD_WIDTH #define SCR_YSIZE LCD_HEIGHT -#define RT_HW_LCD_WIDTH LCD_WIDTH -#define RT_HW_LCD_HEIGHT LCD_HEIGHT +#define RT_HW_LCD_WIDTH LCD_WIDTH +#define RT_HW_LCD_HEIGHT LCD_HEIGHT -#define MVAL (13) -#define MVAL_USED (0) //0=each frame 1=rate by MVAL -#define INVVDEN (1) //0=normal 1=inverted -#define BSWP (0) //Byte swap control -#define HWSWP (1) //Half word swap control +#define MVAL (13) +#define MVAL_USED (0) //0=each frame 1=rate by MVAL +#define INVVDEN (1) //0=normal 1=inverted +#define BSWP (0) //Byte swap control +#define HWSWP (1) //Half word swap control -#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) -#define GPB1_TO_1() (GPBDAT |= 0x0002) -#define GPB1_TO_0() (GPBDAT &= 0xfffd) +#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) +#define GPB1_TO_1() (GPBDAT |= 0x0002) +#define GPB1_TO_0() (GPBDAT &= 0xfffd) #define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8) -#define S3C2410_LCDCON1_MMODE (1<<7) -#define S3C2410_LCDCON1_DSCAN4 (0<<5) -#define S3C2410_LCDCON1_STN4 (1<<5) -#define S3C2410_LCDCON1_STN8 (2<<5) -#define S3C2410_LCDCON1_TFT (3<<5) +#define S3C2410_LCDCON1_MMODE (1<<7) +#define S3C2410_LCDCON1_DSCAN4 (0<<5) +#define S3C2410_LCDCON1_STN4 (1<<5) +#define S3C2410_LCDCON1_STN8 (2<<5) +#define S3C2410_LCDCON1_TFT (3<<5) -#define S3C2410_LCDCON1_STN1BPP (0<<1) +#define S3C2410_LCDCON1_STN1BPP (0<<1) #define S3C2410_LCDCON1_STN2GREY (1<<1) #define S3C2410_LCDCON1_STN4GREY (2<<1) -#define S3C2410_LCDCON1_STN8BPP (3<<1) +#define S3C2410_LCDCON1_STN8BPP (3<<1) #define S3C2410_LCDCON1_STN12BPP (4<<1) -#define S3C2410_LCDCON1_TFT1BPP (8<<1) -#define S3C2410_LCDCON1_TFT2BPP (9<<1) -#define S3C2410_LCDCON1_TFT4BPP (10<<1) -#define S3C2410_LCDCON1_TFT8BPP (11<<1) +#define S3C2410_LCDCON1_TFT1BPP (8<<1) +#define S3C2410_LCDCON1_TFT2BPP (9<<1) +#define S3C2410_LCDCON1_TFT4BPP (10<<1) +#define S3C2410_LCDCON1_TFT8BPP (11<<1) #define S3C2410_LCDCON1_TFT16BPP (12<<1) #define S3C2410_LCDCON1_TFT24BPP (13<<1) -#define S3C2410_LCDCON1_ENVID (1) +#define S3C2410_LCDCON1_ENVID (1) #define S3C2410_LCDCON1_MODEMASK 0x1E -#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) +#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) #define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14) -#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) -#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) +#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) +#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) #define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF) #define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF) #define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F) -#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) -#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) +#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) +#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) #define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8) -#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) +#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) #define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0) #define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F) #define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) -#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) -#define S3C2410_LCDCON4_WLH(x) ((x) << 0) +#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) +#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) +#define S3C2410_LCDCON4_WLH(x) ((x) << 0) #define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON5_BPP24BL (1<<12) -#define S3C2410_LCDCON5_FRM565 (1<<11) -#define S3C2410_LCDCON5_INVVCLK (1<<10) +#define S3C2410_LCDCON5_BPP24BL (1<<12) +#define S3C2410_LCDCON5_FRM565 (1<<11) +#define S3C2410_LCDCON5_INVVCLK (1<<10) #define S3C2410_LCDCON5_INVVLINE (1<<9) #define S3C2410_LCDCON5_INVVFRAME (1<<8) -#define S3C2410_LCDCON5_INVVD (1<<7) -#define S3C2410_LCDCON5_INVVDEN (1<<6) +#define S3C2410_LCDCON5_INVVD (1<<7) +#define S3C2410_LCDCON5_INVVDEN (1<<6) #define S3C2410_LCDCON5_INVPWREN (1<<5) -#define S3C2410_LCDCON5_INVLEND (1<<4) -#define S3C2410_LCDCON5_PWREN (1<<3) -#define S3C2410_LCDCON5_ENLEND (1<<2) -#define S3C2410_LCDCON5_BSWP (1<<1) -#define S3C2410_LCDCON5_HWSWP (1<<0) +#define S3C2410_LCDCON5_INVLEND (1<<4) +#define S3C2410_LCDCON5_PWREN (1<<3) +#define S3C2410_LCDCON5_ENLEND (1<<2) +#define S3C2410_LCDCON5_BSWP (1<<1) +#define S3C2410_LCDCON5_HWSWP (1<<0) -#define S3C2410_LCDINT_FRSYNC (1<<1) +#define S3C2410_LCDINT_FRSYNC (1<<1) volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; //volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; @@ -125,122 +125,122 @@ static void lcd_power_enable(int invpwren, int pwren) static void lcd_envid_on_off(int onoff) { - if(onoff==1) - /*ENVID=ON*/ - LCDCON1|=1; - else - /*ENVID Off*/ - LCDCON1 =LCDCON1 & 0x3fffe; + if(onoff==1) + /*ENVID=ON*/ + LCDCON1|=1; + else + /*ENVID Off*/ + LCDCON1 =LCDCON1 & 0x3fffe; } //********************** BOARD LCD backlight **************************** static void LcdBkLtSet(rt_uint32_t HiRatio) { -#define FREQ_PWM1 1000 - if(!HiRatio) - { - GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output - GPBDAT &= ~(1<<1); - return; - } - GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; +#define FREQ_PWM1 1000 + if(!HiRatio) + { + GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output + GPBDAT &= ~(1<<1); + return; + } + GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; - if( HiRatio > 100 ) HiRatio = 100 ; + if( HiRatio > 100 ) HiRatio = 100 ; - TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 + TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 - TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 - TCFG0 |= 15; //prescaler = 15+1 + TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 + TCFG0 |= 15; //prescaler = 15+1 - TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 - TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 + TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 + TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 - TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low - TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high + TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low + TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high - TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; - TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) -{ - GPB1_TO_OUT(); - GPB1_TO_1(); +{ + GPB1_TO_OUT(); + GPB1_TO_1(); - GPCUP = 0x00000000; - GPCCON = 0xaaaa02a9; + GPCUP = 0x00000000; + GPCCON = 0xaaaa02a9; - GPDUP = 0x00000000; - GPDCON = 0xaaaaaaaa; + GPDUP = 0x00000000; + GPDCON = 0xaaaaaaaa; -#define M5D(n) ((n)&0x1fffff) +#define M5D(n) ((n)&0x1fffff) #define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) - LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); - LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); - LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); - LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); + LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); + LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); + LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); + LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); #if !defined(LCD_CON5) #define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0)) #endif - LCDCON5 = LCD_CON5; + LCDCON5 = LCD_CON5; - LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0); - LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); - LCDSADDR3 = LCD_WIDTH; + LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0); + LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); + LCDSADDR3 = LCD_WIDTH; - LCDINTMSK |= (3); - LPCSEL &= (~7) ; - TPAL=0; + LCDINTMSK |= (3); + LPCSEL &= (~7) ; + TPAL=0; - LcdBkLtSet(70) ; - lcd_power_enable(0, 1); - lcd_envid_on_off(1); + LcdBkLtSet(70) ; + lcd_power_enable(0, 1); + lcd_envid_on_off(1); - return RT_EOK; + return RT_EOK; } static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_lcd_init(void) { - rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); + if (lcd == RT_NULL) return; /* no memory yet */ + + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; - _lcd_info.bits_per_pixel = 16; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; - _lcd_info.framebuffer = (void*)_rt_framebuffer; - _lcd_info.width = LCD_WIDTH; - _lcd_info.height = LCD_HEIGHT; + /* init device structure */ + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* init device structure */ - lcd->type = RT_Device_Class_Unknown; - lcd->init = rt_lcd_init; - lcd->open = RT_NULL; - lcd->close = RT_NULL; - lcd->control = rt_lcd_control; - lcd->user_data = (void*)&_lcd_info; - - /* register lcd device to RT-Thread */ - rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/drivers/lcd_x35.c b/bsp/mini2440/drivers/lcd_x35.c index d3f547df1d..1bb6b9d907 100644 --- a/bsp/mini2440/drivers/lcd_x35.c +++ b/bsp/mini2440/drivers/lcd_x35.c @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes * 2010-01-01 bernard first version from QiuYi's driver - * 2011-07-13 Manoel Modifications on lcd_n35.c to support X35 LCD + * 2011-07-13 Manoel Modifications on lcd_n35.c to support X35 LCD * ACX502BMU - 7522J16D SONY */ @@ -25,7 +25,7 @@ #define LCD_HSYNC_LEN 5 // hsync #define LCD_UPPER_MARGIN 1 // margin_top -#define LCD_LOWER_MARGIN 3 // margin_botton +#define LCD_LOWER_MARGIN 3 // margin_botton #define LCD_VSYNC_LEN 9 // vsync #define LCD_XSIZE LCD_WIDTH @@ -33,82 +33,82 @@ #define SCR_XSIZE LCD_WIDTH #define SCR_YSIZE LCD_HEIGHT -#define RT_HW_LCD_WIDTH LCD_WIDTH -#define RT_HW_LCD_HEIGHT LCD_HEIGHT +#define RT_HW_LCD_WIDTH LCD_WIDTH +#define RT_HW_LCD_HEIGHT LCD_HEIGHT -#define MVAL (13) -#define MVAL_USED (0) //0=each frame 1=rate by MVAL -#define INVVDEN (1) //0=normal 1=inverted -#define BSWP (0) //Byte swap control -#define HWSWP (1) //Half word swap control +#define MVAL (13) +#define MVAL_USED (0) //0=each frame 1=rate by MVAL +#define INVVDEN (1) //0=normal 1=inverted +#define BSWP (0) //Byte swap control +#define HWSWP (1) //Half word swap control -#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) -#define GPB1_TO_1() (GPBDAT |= 0x0002) -#define GPB1_TO_0() (GPBDAT &= 0xfffd) +#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004) +#define GPB1_TO_1() (GPBDAT |= 0x0002) +#define GPB1_TO_0() (GPBDAT &= 0xfffd) #define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8) -#define S3C2410_LCDCON1_MMODE (1<<7) -#define S3C2410_LCDCON1_DSCAN4 (0<<5) -#define S3C2410_LCDCON1_STN4 (1<<5) -#define S3C2410_LCDCON1_STN8 (2<<5) -#define S3C2410_LCDCON1_TFT (3<<5) +#define S3C2410_LCDCON1_MMODE (1<<7) +#define S3C2410_LCDCON1_DSCAN4 (0<<5) +#define S3C2410_LCDCON1_STN4 (1<<5) +#define S3C2410_LCDCON1_STN8 (2<<5) +#define S3C2410_LCDCON1_TFT (3<<5) -#define S3C2410_LCDCON1_STN1BPP (0<<1) +#define S3C2410_LCDCON1_STN1BPP (0<<1) #define S3C2410_LCDCON1_STN2GREY (1<<1) #define S3C2410_LCDCON1_STN4GREY (2<<1) -#define S3C2410_LCDCON1_STN8BPP (3<<1) +#define S3C2410_LCDCON1_STN8BPP (3<<1) #define S3C2410_LCDCON1_STN12BPP (4<<1) -#define S3C2410_LCDCON1_TFT1BPP (8<<1) -#define S3C2410_LCDCON1_TFT2BPP (9<<1) -#define S3C2410_LCDCON1_TFT4BPP (10<<1) -#define S3C2410_LCDCON1_TFT8BPP (11<<1) +#define S3C2410_LCDCON1_TFT1BPP (8<<1) +#define S3C2410_LCDCON1_TFT2BPP (9<<1) +#define S3C2410_LCDCON1_TFT4BPP (10<<1) +#define S3C2410_LCDCON1_TFT8BPP (11<<1) #define S3C2410_LCDCON1_TFT16BPP (12<<1) #define S3C2410_LCDCON1_TFT24BPP (13<<1) -#define S3C2410_LCDCON1_ENVID (1) +#define S3C2410_LCDCON1_ENVID (1) #define S3C2410_LCDCON1_MODEMASK 0x1E -#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) +#define S3C2410_LCDCON2_VBPD(x) ((x) << 24) #define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14) -#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) -#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) +#define S3C2410_LCDCON2_VFPD(x) ((x) << 6) +#define S3C2410_LCDCON2_VSPW(x) ((x) << 0) #define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF) #define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF) #define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F) -#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) -#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) +#define S3C2410_LCDCON3_HBPD(x) ((x) << 19) +#define S3C2410_LCDCON3_WDLY(x) ((x) << 19) #define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8) -#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) +#define S3C2410_LCDCON3_HFPD(x) ((x) << 0) #define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0) #define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F) #define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) -#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) -#define S3C2410_LCDCON4_WLH(x) ((x) << 0) +#define S3C2410_LCDCON4_MVAL(x) ((x) << 8) +#define S3C2410_LCDCON4_HSPW(x) ((x) << 0) +#define S3C2410_LCDCON4_WLH(x) ((x) << 0) #define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF) -#define S3C2410_LCDCON5_BPP24BL (1<<12) -#define S3C2410_LCDCON5_FRM565 (1<<11) -#define S3C2410_LCDCON5_INVVCLK (1<<10) +#define S3C2410_LCDCON5_BPP24BL (1<<12) +#define S3C2410_LCDCON5_FRM565 (1<<11) +#define S3C2410_LCDCON5_INVVCLK (1<<10) #define S3C2410_LCDCON5_INVVLINE (1<<9) #define S3C2410_LCDCON5_INVVFRAME (1<<8) -#define S3C2410_LCDCON5_INVVD (1<<7) -#define S3C2410_LCDCON5_INVVDEN (1<<6) +#define S3C2410_LCDCON5_INVVD (1<<7) +#define S3C2410_LCDCON5_INVVDEN (1<<6) #define S3C2410_LCDCON5_INVPWREN (1<<5) -#define S3C2410_LCDCON5_INVLEND (1<<4) -#define S3C2410_LCDCON5_PWREN (1<<3) -#define S3C2410_LCDCON5_ENLEND (1<<2) -#define S3C2410_LCDCON5_BSWP (1<<1) -#define S3C2410_LCDCON5_HWSWP (1<<0) +#define S3C2410_LCDCON5_INVLEND (1<<4) +#define S3C2410_LCDCON5_PWREN (1<<3) +#define S3C2410_LCDCON5_ENLEND (1<<2) +#define S3C2410_LCDCON5_BSWP (1<<1) +#define S3C2410_LCDCON5_HWSWP (1<<0) -#define S3C2410_LCDINT_FRSYNC (1<<1) +#define S3C2410_LCDINT_FRSYNC (1<<1) static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; //static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; @@ -127,61 +127,61 @@ static void lcd_power_enable(int invpwren, int pwren) static void lcd_envid_on_off(int onoff) { - if(onoff==1) - /*ENVID=ON*/ - LCDCON1|=1; - else - /*ENVID Off*/ - LCDCON1 =LCDCON1 & 0x3fffe; + if(onoff==1) + /*ENVID=ON*/ + LCDCON1|=1; + else + /*ENVID Off*/ + LCDCON1 =LCDCON1 & 0x3fffe; } //********************** BOARD LCD backlight **************************** static void LcdBkLtSet(rt_uint32_t HiRatio) { -#define FREQ_PWM1 1000 - if(!HiRatio) - { - GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output - GPBDAT &= ~(1<<1); - return; - } - GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; +#define FREQ_PWM1 1000 + if(!HiRatio) + { + GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1设置为output + GPBDAT &= ~(1<<1); + return; + } + GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; - if( HiRatio > 100 ) HiRatio = 100 ; + if( HiRatio > 100 ) HiRatio = 100 ; - TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 + TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 - TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 - TCFG0 |= 15; //prescaler = 15+1 + TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0 + TCFG0 |= 15; //prescaler = 15+1 - TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 - TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 + TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16 + TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16 - TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low - TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high + TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low + TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high - TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; - TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ; + TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) -{ - GPB1_TO_OUT(); - GPB1_TO_1(); +{ + GPB1_TO_OUT(); + GPB1_TO_1(); - GPCUP = 0x00000000; - GPCCON = 0xaaaa02a9; + GPCUP = 0x00000000; + GPCCON = 0xaaaa02a9; - GPDUP = 0x00000000; - GPDCON = 0xaaaaaaaa; + GPDUP = 0x00000000; + GPDCON = 0xaaaaaaaa; -#define M5D(n) ((n)&0x1fffff) +#define M5D(n) ((n)&0x1fffff) #define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) - LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); - LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); - LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); - LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); + LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); + LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); + LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); + LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0); #define LCD_CON5 (S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVDEN | S3C2410_LCDCON5_INVVFRAME | \ S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN| S3C2410_LCDCON5_HWSWP) @@ -195,57 +195,57 @@ S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN| S3C2 LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1); LCDSADDR3 = LCD_WIDTH; - LCDINTMSK |= (3); - LPCSEL &= (~7) ; - TPAL=0; + LCDINTMSK |= (3); + LPCSEL &= (~7) ; + TPAL=0; - LcdBkLtSet(70) ; - lcd_power_enable(0, 1); - lcd_envid_on_off(1); + LcdBkLtSet(70) ; + lcd_power_enable(0, 1); + lcd_envid_on_off(1); - return RT_EOK; + return RT_EOK; } static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RTGRAPHIC_CTRL_RECT_UPDATE: - break; - case RTGRAPHIC_CTRL_POWERON: - break; - case RTGRAPHIC_CTRL_POWEROFF: - break; - case RTGRAPHIC_CTRL_GET_INFO: - rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); - break; - case RTGRAPHIC_CTRL_SET_MODE: - break; - } + switch (cmd) + { + case RTGRAPHIC_CTRL_RECT_UPDATE: + break; + case RTGRAPHIC_CTRL_POWERON: + break; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: + break; + } - return RT_EOK; + return RT_EOK; } void rt_hw_lcd_init(void) { - rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); + if (lcd == RT_NULL) return; /* no memory yet */ + + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; - _lcd_info.bits_per_pixel = 16; - _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; - _lcd_info.framebuffer = (void*)_rt_framebuffer; - _lcd_info.width = LCD_WIDTH; - _lcd_info.height = LCD_HEIGHT; + /* init device structure */ + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* init device structure */ - lcd->type = RT_Device_Class_Unknown; - lcd->init = rt_lcd_init; - lcd->open = RT_NULL; - lcd->close = RT_NULL; - lcd->control = rt_lcd_control; - lcd->user_data = (void*)&_lcd_info; - - /* register lcd device to RT-Thread */ - rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/drivers/led.c b/bsp/mini2440/drivers/led.c index 3cc830012e..88e83d33ef 100644 --- a/bsp/mini2440/drivers/led.c +++ b/bsp/mini2440/drivers/led.c @@ -18,19 +18,19 @@ void rt_hw_led_init(void) { - /* GPB5,GPB6,GPB7,GPB8 for LED */ - GPBCON = GPBCON & (~(0xff << 10)) | (0x55 << 10); - GPBUP |= (0x0f << 5); + /* GPB5,GPB6,GPB7,GPB8 for LED */ + GPBCON = GPBCON & (~(0xff << 10)) | (0x55 << 10); + GPBUP |= (0x0f << 5); } void rt_hw_led_on(unsigned char value) { - GPBDAT &= ~ ((value & 0x0f) << 5); + GPBDAT &= ~ ((value & 0x0f) << 5); } void rt_hw_led_off(unsigned char value) { - GPBDAT |= (value & 0x0f) << 5; + GPBDAT |= (value & 0x0f) << 5; } /*@}*/ diff --git a/bsp/mini2440/drivers/sdcard.c b/bsp/mini2440/drivers/sdcard.c index 87ab4a27e7..0f1555f4ce 100644 --- a/bsp/mini2440/drivers/sdcard.c +++ b/bsp/mini2440/drivers/sdcard.c @@ -286,15 +286,15 @@ static int sd_ocr(void) rt_err_t sd_cmd8(void) { - SDICARG = 0x000001AA; + SDICARG = 0x000001AA; SDICCON = (0x1<<9) | (0x1<<8) | 0x48; //sht_resp, wait_resp, start if (sd_cmd_end(8, 1) == RT_ERROR) return RT_ERROR; SDICSTA = 0xa00; - + if ((SDIRSP0&0x1aa) == 0x1aa) - return RT_EOK; - else + return RT_EOK; + else return RT_ERROR; } diff --git a/bsp/mini2440/drivers/touch.c b/bsp/mini2440/drivers/touch.c index 2c9f8ca52f..d2e20c9db4 100644 --- a/bsp/mini2440/drivers/touch.c +++ b/bsp/mini2440/drivers/touch.c @@ -7,7 +7,7 @@ * Date Author Notes * 2010-01-01 Yi.Qiu first version */ - + #include <rthw.h> #include <rtthread.h> #include <s3c24x0.h> @@ -22,473 +22,473 @@ #include "touch.h" /* ADCCON Register Bits */ -#define S3C2410_ADCCON_ECFLG (1<<15) -#define S3C2410_ADCCON_PRSCEN (1<<14) -#define S3C2410_ADCCON_PRSCVL(x) (((x)&0xFF)<<6) -#define S3C2410_ADCCON_PRSCVLMASK (0xFF<<6) -#define S3C2410_ADCCON_SELMUX(x) (((x)&0x7)<<3) -#define S3C2410_ADCCON_MUXMASK (0x7<<3) -#define S3C2410_ADCCON_STDBM (1<<2) -#define S3C2410_ADCCON_READ_START (1<<1) -#define S3C2410_ADCCON_ENABLE_START (1<<0) -#define S3C2410_ADCCON_STARTMASK (0x3<<0) +#define S3C2410_ADCCON_ECFLG (1<<15) +#define S3C2410_ADCCON_PRSCEN (1<<14) +#define S3C2410_ADCCON_PRSCVL(x) (((x)&0xFF)<<6) +#define S3C2410_ADCCON_PRSCVLMASK (0xFF<<6) +#define S3C2410_ADCCON_SELMUX(x) (((x)&0x7)<<3) +#define S3C2410_ADCCON_MUXMASK (0x7<<3) +#define S3C2410_ADCCON_STDBM (1<<2) +#define S3C2410_ADCCON_READ_START (1<<1) +#define S3C2410_ADCCON_ENABLE_START (1<<0) +#define S3C2410_ADCCON_STARTMASK (0x3<<0) /* ADCTSC Register Bits */ -#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */ -#define S3C2410_ADCTSC_YM_SEN (1<<7) -#define S3C2410_ADCTSC_YP_SEN (1<<6) -#define S3C2410_ADCTSC_XM_SEN (1<<5) -#define S3C2410_ADCTSC_XP_SEN (1<<4) -#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3) -#define S3C2410_ADCTSC_AUTO_PST (1<<2) -#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0) +#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */ +#define S3C2410_ADCTSC_YM_SEN (1<<7) +#define S3C2410_ADCTSC_YP_SEN (1<<6) +#define S3C2410_ADCTSC_XM_SEN (1<<5) +#define S3C2410_ADCTSC_XP_SEN (1<<4) +#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3) +#define S3C2410_ADCTSC_AUTO_PST (1<<2) +#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0) /* ADCDAT0 Bits */ -#define S3C2410_ADCDAT0_UPDOWN (1<<15) -#define S3C2410_ADCDAT0_AUTO_PST (1<<14) -#define S3C2410_ADCDAT0_XY_PST (0x3<<12) -#define S3C2410_ADCDAT0_XPDATA_MASK (0x03FF) +#define S3C2410_ADCDAT0_UPDOWN (1<<15) +#define S3C2410_ADCDAT0_AUTO_PST (1<<14) +#define S3C2410_ADCDAT0_XY_PST (0x3<<12) +#define S3C2410_ADCDAT0_XPDATA_MASK (0x03FF) /* ADCDAT1 Bits */ -#define S3C2410_ADCDAT1_UPDOWN (1<<15) -#define S3C2410_ADCDAT1_AUTO_PST (1<<14) -#define S3C2410_ADCDAT1_XY_PST (0x3<<12) -#define S3C2410_ADCDAT1_YPDATA_MASK (0x03FF) +#define S3C2410_ADCDAT1_UPDOWN (1<<15) +#define S3C2410_ADCDAT1_AUTO_PST (1<<14) +#define S3C2410_ADCDAT1_XY_PST (0x3<<12) +#define S3C2410_ADCDAT1_YPDATA_MASK (0x03FF) #define WAIT4INT(x) (((x)<<8) | \ - S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \ - S3C2410_ADCTSC_XY_PST(3)) + S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \ + S3C2410_ADCTSC_XY_PST(3)) -#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \ - S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0)) +#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \ + S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0)) -#define X_MIN 74 -#define X_MAX 934 -#define Y_MIN 920 -#define Y_MAX 89 +#define X_MIN 74 +#define X_MAX 934 +#define Y_MIN 920 +#define Y_MAX 89 struct s3c2410ts { - long xp; - long yp; - int count; - int shift; + long xp; + long yp; + int count; + int shift; - int delay; - int presc; + int delay; + int presc; - char phys[32]; + char phys[32]; }; static struct s3c2410ts ts; struct rtgui_touch_device { - struct rt_device parent; + struct rt_device parent; + + rt_timer_t poll_timer; + rt_uint16_t x, y; - rt_timer_t poll_timer; - rt_uint16_t x, y; + rt_bool_t calibrating; + rt_touch_calibration_func_t calibration_func; - rt_bool_t calibrating; - rt_touch_calibration_func_t calibration_func; + rt_touch_eventpost_func_t eventpost_func; + void *eventpost_param; - rt_touch_eventpost_func_t eventpost_func; - void *eventpost_param; + rt_uint16_t min_x, max_x; + rt_uint16_t min_y, max_y; - rt_uint16_t min_x, max_x; - rt_uint16_t min_y, max_y; + rt_uint16_t width; + rt_uint16_t height; - rt_uint16_t width; - rt_uint16_t height; - - rt_bool_t first_down_report; + rt_bool_t first_down_report; }; static struct rtgui_touch_device *touch = RT_NULL; #ifdef RT_USING_RTGUI static void report_touch_input(int updown) { - struct rtgui_event_mouse emouse; + struct rtgui_event_mouse emouse; + + RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse); + emouse.wid = RT_NULL; + + /* set emouse button */ + emouse.button = RTGUI_MOUSE_BUTTON_LEFT; + emouse.parent.sender = RT_NULL; - RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse); - emouse.wid = RT_NULL; + if (updown) + { + ts.xp = ts.xp / ts.count; + ts.yp = ts.yp / ts.count;; - /* set emouse button */ - emouse.button = RTGUI_MOUSE_BUTTON_LEFT; - emouse.parent.sender = RT_NULL; - - if (updown) - { - ts.xp = ts.xp / ts.count; - ts.yp = ts.yp / ts.count;; + if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) + { + touch->x = ts.xp; + touch->y = ts.yp; + } + else + { + if (touch->max_x > touch->min_x) + { + touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x); + } + else + { + touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x); + } - if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) - { - touch->x = ts.xp; - touch->y = ts.yp; - } - else - { - if (touch->max_x > touch->min_x) - { - touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x); - } - else - { - touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x); - } + if (touch->max_y > touch->min_y) + { + touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y); + } + else + { + touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y); + } + } - if (touch->max_y > touch->min_y) - { - touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y); - } - else - { - touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y); - } - } + emouse.x = touch->x; + emouse.y = touch->y; + if (touch->first_down_report == RT_TRUE) + { + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button |= RTGUI_MOUSE_BUTTON_DOWN; + } + else + { + emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION; + emouse.button = 0; + } + } + else + { + emouse.x = touch->x; + emouse.y = touch->y; + emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; + emouse.button |= RTGUI_MOUSE_BUTTON_UP; + if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) + { + /* callback function */ + touch->calibration_func(emouse.x, emouse.y); + } + } - emouse.x = touch->x; - emouse.y = touch->y; - if (touch->first_down_report == RT_TRUE) - { - emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; - emouse.button |= RTGUI_MOUSE_BUTTON_DOWN; - } - else - { - emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION; - emouse.button = 0; - } - } - else - { - emouse.x = touch->x; - emouse.y = touch->y; - emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON; - emouse.button |= RTGUI_MOUSE_BUTTON_UP; - if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) - { - /* callback function */ - touch->calibration_func(emouse.x, emouse.y); - } - } + /* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up", + touch->x, touch->y); */ - /* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up", - touch->x, touch->y); */ - - /* send event to server */ - if (touch->calibrating != RT_TRUE) - { - rtgui_server_post_event((&emouse.parent), sizeof(emouse)); - } + /* send event to server */ + if (touch->calibrating != RT_TRUE) + { + rtgui_server_post_event((&emouse.parent), sizeof(emouse)); + } } #else static void report_touch_input(int updown) { - struct rt_touch_event touch_event; + struct rt_touch_event touch_event; - if (updown) - { - ts.xp = ts.xp / ts.count; - ts.yp = ts.yp / ts.count; + if (updown) + { + ts.xp = ts.xp / ts.count; + ts.yp = ts.yp / ts.count; - if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) - { - touch->x = ts.xp; - touch->y = ts.yp; - } - else - { - if (touch->max_x > touch->min_x) - { - touch->x = touch->width * ( ts.xp - touch->min_x ) / (touch->max_x-touch->min_x); - } - else - { - touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x); - } + if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) + { + touch->x = ts.xp; + touch->y = ts.yp; + } + else + { + if (touch->max_x > touch->min_x) + { + touch->x = touch->width * ( ts.xp - touch->min_x ) / (touch->max_x-touch->min_x); + } + else + { + touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x); + } - if (touch->max_y > touch->min_y) - { - touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y); - } - else - { - touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y); - } - } + if (touch->max_y > touch->min_y) + { + touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y); + } + else + { + touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y); + } + } - touch_event.x = touch->x; - touch_event.y = touch->y; - touch_event.pressed = 1; + touch_event.x = touch->x; + touch_event.y = touch->y; + touch_event.pressed = 1; - if (touch->first_down_report == RT_TRUE) - { - if (touch->calibrating != RT_TRUE && touch->eventpost_func) - { - touch->eventpost_func(touch->eventpost_param, &touch_event); - } - } - } - else - { - touch_event.x = touch->x; - touch_event.y = touch->y; - touch_event.pressed = 0; - - if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) - { - /* callback function */ - touch->calibration_func(touch_event.x, touch_event.y); - } + if (touch->first_down_report == RT_TRUE) + { + if (touch->calibrating != RT_TRUE && touch->eventpost_func) + { + touch->eventpost_func(touch->eventpost_param, &touch_event); + } + } + } + else + { + touch_event.x = touch->x; + touch_event.y = touch->y; + touch_event.pressed = 0; - if (touch->calibrating != RT_TRUE && touch->eventpost_func) - { - touch->eventpost_func(touch->eventpost_param, &touch_event); - } - } + if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) + { + /* callback function */ + touch->calibration_func(touch_event.x, touch_event.y); + } + + if (touch->calibrating != RT_TRUE && touch->eventpost_func) + { + touch->eventpost_func(touch->eventpost_param, &touch_event); + } + } } #endif static void touch_timer_fire(void *parameter) { - rt_uint32_t data0; - rt_uint32_t data1; - int updown; + rt_uint32_t data0; + rt_uint32_t data1; + int updown; - data0 = ADCDAT0; - data1 = ADCDAT1; + data0 = ADCDAT0; + data1 = ADCDAT1; - updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN)); + updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN)); - if (updown) - { - if (ts.count != 0) - { - report_touch_input(updown); - } + if (updown) + { + if (ts.count != 0) + { + report_touch_input(updown); + } - ts.xp = 0; - ts.yp = 0; - ts.count = 0; + ts.xp = 0; + ts.yp = 0; + ts.count = 0; - ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST; - ADCCON |= S3C2410_ADCCON_ENABLE_START; - } + ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST; + ADCCON |= S3C2410_ADCCON_ENABLE_START; + } } static void s3c2410_adc_stylus_action(void) { - rt_uint32_t data0; - rt_uint32_t data1; + rt_uint32_t data0; + rt_uint32_t data1; + + data0 = ADCDAT0; + data1 = ADCDAT1; - data0 = ADCDAT0; - data1 = ADCDAT1; - - ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK; - ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK; - ts.count ++; + ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK; + ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK; + ts.count ++; - if (ts.count < (1<<ts.shift)) - { - ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST; - ADCCON |= S3C2410_ADCCON_ENABLE_START; - } - else - { - if (touch->first_down_report) - { - report_touch_input(1); - ts.xp = 0; - ts.yp = 0; - ts.count = 0; - touch->first_down_report = 0; - } - /* start timer */ - rt_timer_start(touch->poll_timer); - ADCTSC = WAIT4INT(1); - } + if (ts.count < (1<<ts.shift)) + { + ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST; + ADCCON |= S3C2410_ADCCON_ENABLE_START; + } + else + { + if (touch->first_down_report) + { + report_touch_input(1); + ts.xp = 0; + ts.yp = 0; + ts.count = 0; + touch->first_down_report = 0; + } + /* start timer */ + rt_timer_start(touch->poll_timer); + ADCTSC = WAIT4INT(1); + } - SUBSRCPND |= BIT_SUB_ADC; + SUBSRCPND |= BIT_SUB_ADC; } static void s3c2410_intc_stylus_updown(void) { - rt_uint32_t data0; - rt_uint32_t data1; - int updown; + rt_uint32_t data0; + rt_uint32_t data1; + int updown; - data0 = ADCDAT0; - data1 = ADCDAT1; + data0 = ADCDAT0; + data1 = ADCDAT1; - updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN)); + updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN)); - /* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */ + /* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */ - if (updown) - { - touch_timer_fire(0); - } - else - { - /* stop timer */ - rt_timer_stop(touch->poll_timer); - touch->first_down_report = RT_TRUE; - if (ts.xp >= 0 && ts.yp >= 0) - { - report_touch_input(updown); - } - ts.count = 0; - ADCTSC = WAIT4INT(0); - } + if (updown) + { + touch_timer_fire(0); + } + else + { + /* stop timer */ + rt_timer_stop(touch->poll_timer); + touch->first_down_report = RT_TRUE; + if (ts.xp >= 0 && ts.yp >= 0) + { + report_touch_input(updown); + } + ts.count = 0; + ADCTSC = WAIT4INT(0); + } - SUBSRCPND |= BIT_SUB_TC; + SUBSRCPND |= BIT_SUB_TC; } static void rt_touch_handler(int irqno) { - if (SUBSRCPND & BIT_SUB_ADC) - { - /* INT_SUB_ADC */ - s3c2410_adc_stylus_action(); - } + if (SUBSRCPND & BIT_SUB_ADC) + { + /* INT_SUB_ADC */ + s3c2410_adc_stylus_action(); + } - if (SUBSRCPND & BIT_SUB_TC) - { - /* INT_SUB_TC */ - s3c2410_intc_stylus_updown(); - } + if (SUBSRCPND & BIT_SUB_TC) + { + /* INT_SUB_TC */ + s3c2410_intc_stylus_updown(); + } - /* clear interrupt */ - INTPND |= (1ul << INTADC); + /* clear interrupt */ + INTPND |= (1ul << INTADC); } /* RT-Thread Device Interface */ static rt_err_t rtgui_touch_init(rt_device_t dev) { - /* init touch screen structure */ - rt_memset(&ts, 0, sizeof(struct s3c2410ts)); + /* init touch screen structure */ + rt_memset(&ts, 0, sizeof(struct s3c2410ts)); - ts.delay = 50000; - ts.presc = 9; - ts.shift = 2; - ts.count = 0; - ts.xp = ts.yp = 0; + ts.delay = 50000; + ts.presc = 9; + ts.shift = 2; + ts.count = 0; + ts.xp = ts.yp = 0; - ADCCON = S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(ts.presc); - ADCDLY = ts.delay; + ADCCON = S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(ts.presc); + ADCDLY = ts.delay; - ADCTSC = WAIT4INT(0); + ADCTSC = WAIT4INT(0); - rt_hw_interrupt_install(INTADC, rt_touch_handler, RT_NULL , "INTADC"); - rt_hw_interrupt_umask(INTADC); + rt_hw_interrupt_install(INTADC, rt_touch_handler, RT_NULL , "INTADC"); + rt_hw_interrupt_umask(INTADC); - /* clear interrupt */ - INTPND |= (1ul << INTADC); + /* clear interrupt */ + INTPND |= (1ul << INTADC); - SUBSRCPND |= BIT_SUB_TC; - SUBSRCPND |= BIT_SUB_ADC; + SUBSRCPND |= BIT_SUB_TC; + SUBSRCPND |= BIT_SUB_ADC; - /* install interrupt handler */ - INTSUBMSK &= ~BIT_SUB_ADC; - INTSUBMSK &= ~BIT_SUB_TC; + /* install interrupt handler */ + INTSUBMSK &= ~BIT_SUB_ADC; + INTSUBMSK &= ~BIT_SUB_TC; - touch->first_down_report = RT_TRUE; + touch->first_down_report = RT_TRUE; - return RT_EOK; + return RT_EOK; } static rt_err_t rtgui_touch_control(rt_device_t dev, int cmd, void *args) { - switch (cmd) - { - case RT_TOUCH_CALIBRATION: - touch->calibrating = RT_TRUE; - touch->calibration_func = (rt_touch_calibration_func_t)args; - break; + switch (cmd) + { + case RT_TOUCH_CALIBRATION: + touch->calibrating = RT_TRUE; + touch->calibration_func = (rt_touch_calibration_func_t)args; + break; - case RT_TOUCH_NORMAL: - touch->calibrating = RT_FALSE; - break; + case RT_TOUCH_NORMAL: + touch->calibrating = RT_FALSE; + break; - case RT_TOUCH_CALIBRATION_DATA: - { - struct calibration_data *data; + case RT_TOUCH_CALIBRATION_DATA: + { + struct calibration_data *data; - data = (struct calibration_data *)args; + data = (struct calibration_data *)args; - /* update */ - touch->min_x = data->min_x; - touch->max_x = data->max_x; - touch->min_y = data->min_y; - touch->max_y = data->max_y; + /* update */ + touch->min_x = data->min_x; + touch->max_x = data->max_x; + touch->min_y = data->min_y; + touch->max_y = data->max_y; - /* - rt_kprintf("min_x = %d, max_x = %d, min_y = %d, max_y = %d\n", - touch->min_x, touch->max_x, touch->min_y, touch->max_y); - */ - } - break; + /* + rt_kprintf("min_x = %d, max_x = %d, min_y = %d, max_y = %d\n", + touch->min_x, touch->max_x, touch->min_y, touch->max_y); + */ + } + break; - case RT_TOUCH_EVENTPOST: - touch->eventpost_func = (rt_touch_eventpost_func_t)args; - break; + case RT_TOUCH_EVENTPOST: + touch->eventpost_func = (rt_touch_eventpost_func_t)args; + break; - case RT_TOUCH_EVENTPOST_PARAM: - touch->eventpost_param = args; - break; - } + case RT_TOUCH_EVENTPOST_PARAM: + touch->eventpost_param = args; + break; + } - return RT_EOK; + return RT_EOK; } void rtgui_touch_hw_init(void) { - rt_err_t result = RT_FALSE; - rt_device_t device = RT_NULL; - struct rt_device_graphic_info info; + rt_err_t result = RT_FALSE; + rt_device_t device = RT_NULL; + struct rt_device_graphic_info info; + + touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device)); + if (touch == RT_NULL) + return; /* no memory yet */ - touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device)); - if (touch == RT_NULL) - return; /* no memory yet */ + /* clear device structure */ + rt_memset(&(touch->parent), 0, sizeof(struct rt_device)); + touch->calibrating = RT_FALSE; + touch->min_x = X_MIN; + touch->max_x = X_MAX; + touch->min_y = Y_MIN; + touch->max_y = Y_MAX; + touch->eventpost_func = RT_NULL; + touch->eventpost_param = RT_NULL; - /* clear device structure */ - rt_memset(&(touch->parent), 0, sizeof(struct rt_device)); - touch->calibrating = RT_FALSE; - touch->min_x = X_MIN; - touch->max_x = X_MAX; - touch->min_y = Y_MIN; - touch->max_y = Y_MAX; - touch->eventpost_func = RT_NULL; - touch->eventpost_param = RT_NULL; + /* init device structure */ + touch->parent.type = RT_Device_Class_Unknown; + touch->parent.init = rtgui_touch_init; + touch->parent.control = rtgui_touch_control; + touch->parent.user_data = RT_NULL; - /* init device structure */ - touch->parent.type = RT_Device_Class_Unknown; - touch->parent.init = rtgui_touch_init; - touch->parent.control = rtgui_touch_control; - touch->parent.user_data = RT_NULL; + device = rt_device_find("lcd"); + if (device == RT_NULL) + return; /* no this device */ - device = rt_device_find("lcd"); - if (device == RT_NULL) - return; /* no this device */ + /* get graphic device info */ + result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); + if (result != RT_EOK) + { - /* get graphic device info */ - result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); - if (result != RT_EOK) - { + /* get device information failed */ - /* get device information failed */ + return; + } - return; - } + touch->width = info.width; + touch->height = info.height; - touch->width = info.width; - touch->height = info.height; - - /* create 1/8 second timer */ - touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL, - RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC); + /* create 1/8 second timer */ + touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL, + RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC); - /* register touch device to RT-Thread */ - rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); + /* register touch device to RT-Thread */ + rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); } |
