diff --git a/bsp/mini2440/.config b/bsp/mini2440/.config index e10689caa87129e3a513b1d3c44aa3f0f9616399..1e1372162c24f6c9f740998632ebfe2295a7280d 100644 --- a/bsp/mini2440/.config +++ b/bsp/mini2440/.config @@ -161,7 +161,13 @@ CONFIG_RT_USING_PIN=y # CONFIG_RT_USING_MTD_NAND is not set # CONFIG_RT_USING_PM is not set # CONFIG_RT_USING_RTC is not set -# CONFIG_RT_USING_SDIO is not set +CONFIG_RT_USING_SDIO=y +CONFIG_RT_SDIO_STACK_SIZE=512 +CONFIG_RT_SDIO_THREAD_PRIORITY=15 +CONFIG_RT_MMCSD_STACK_SIZE=1024 +CONFIG_RT_MMCSD_THREAD_PREORITY=22 +CONFIG_RT_MMCSD_MAX_PARTITION=16 +# CONFIG_RT_SDIO_DEBUG is not set # CONFIG_RT_USING_SPI is not set # CONFIG_RT_USING_WDT is not set # CONFIG_RT_USING_AUDIO is not set diff --git a/bsp/mini2440/Kconfig b/bsp/mini2440/Kconfig index 44da5183ebe7509fb9f9434099f630d0cc1574ba..48e4f26a38ab111b9ee8fc5c806e655aebdc3f95 100644 --- a/bsp/mini2440/Kconfig +++ b/bsp/mini2440/Kconfig @@ -16,12 +16,33 @@ config PKGS_DIR default "packages" config BOARD_MINI2440 - bool "mini2440" + bool select ARCH_ARM_ARM9 select RT_USING_COMPONENTS_INIT select RT_USING_USER_MAIN default y +choice + prompt "Lcd for mini2440" + default RT_MINI2440_LCD_T35 + depends on PKG_USING_GUIENGINE + + config RT_MINI2440_LCD_A70 + bool "A70" + + config RT_MINI2440_LCD_T43 + bool "T43" + + config RT_MINI2440_LCD_N35 + bool "N35" + + config RT_MINI2440_LCD_T35 + bool "T35" + + config RT_MINI2440_LCD_X35 + bool "X35" +endchoice + source "$RTT_DIR/Kconfig" source "$PKGS_DIR/Kconfig" diff --git a/bsp/mini2440/applications/main.c b/bsp/mini2440/applications/main.c index a67ff93f7a81879ab4ba136e854a621063090ab1..923f014469847d313582c9b27a1fc26fc2622fe9 100644 --- a/bsp/mini2440/applications/main.c +++ b/bsp/mini2440/applications/main.c @@ -5,9 +5,24 @@ #include "led.h" +#ifdef PKG_USING_GUIENGINE +#include +#endif + int main(void) { - printf("hello rt-thread\n"); + rt_device_t device; + + printf("hello rt-thread\n"); + +#ifdef PKG_USING_GUIENGINE + device = rt_device_find("lcd"); + if (device) + { + rtgui_graphic_set_device(device); + } +#endif + while (1) { diff --git a/bsp/mini2440/applications/mnt.c b/bsp/mini2440/applications/mnt.c index 50ade3a3eb5605a9625fc3316b1ec227cb1bf99e..2e1ae80692e4c77e023ee925e5ab5671dcfad71e 100644 --- a/bsp/mini2440/applications/mnt.c +++ b/bsp/mini2440/applications/mnt.c @@ -6,15 +6,28 @@ int mnt_init(void) { - if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) + rt_uint32_t tryCnt = 5; + rt_device_t dev; + + while(tryCnt--) { - rt_kprintf("File System initialized!\n"); + dev = rt_device_find("sd0"); + if(dev != RT_NULL) + { + break; + } + rt_thread_mdelay(500); + } + + if(dfs_mount("sd0", "/", "elm", 0, 0) == 0) + { + rt_kprintf("File System initialized!\n"); } else { rt_kprintf("File System initialzation failed!\n"); } - + return RT_EOK; } INIT_ENV_EXPORT(mnt_init); diff --git a/bsp/mini2440/drivers/SConscript b/bsp/mini2440/drivers/SConscript index 2c81f19e33726c6270f9870047a85562a96ea63b..902b48320d37f472ad95e1438fb121ce3f660372 100644 --- a/bsp/mini2440/drivers/SConscript +++ b/bsp/mini2440/drivers/SConscript @@ -8,30 +8,30 @@ cwd = os.path.join(str(Dir('#')), 'drivers') src = Split(""" board.c led.c +key.c uart.c """) -if GetDepend('RT_USING_DFS'): - src += ['sdcard.c'] - if GetDepend('RT_USING_LWIP'): src += ['dm9000.c'] -if GetDepend('PKG_USING_GUIENGINE'): - src += ['touch.c', 'key.c'] +if GetDepend('RT_MINI2440_LCD_A70'): + src += ['lcd_a70.c'] +if GetDepend('RT_MINI2440_LCD_T43'): + src += ['lcd_t43.c'] +if GetDepend('RT_MINI2440_LCD_N35'): + src += ['lcd_n35.c'] +if GetDepend('RT_MINI2440_LCD_T35'): + src += ['lcd_t35.c'] +if GetDepend('RT_MINI2440_LCD_X35'): + src += ['lcd_x35.c'] -if GetDepend('RT_USING_RTI'): - src += ['rti_stub.c'] - if GetDepend('PKG_USING_GUIENGINE'): - if rtconfig.RT_USING_LCD_TYPE == 'PNL_A70': - src += ['lcd_a70.c'] - elif rtconfig.RT_USING_LCD_TYPE == 'PNL_N35': - src += ['lcd_n35.c'] - elif rtconfig.RT_USING_LCD_TYPE == 'PNL_T35': - src += ['lcd_t35.c'] - elif rtconfig.RT_USING_LCD_TYPE == 'PNL_X35': - src += ['lcd_x35.c'] + src += ['touch.c'] + +if GetDepend('RT_USING_SDIO'): + src += ['s3cmci.c'] + CPPPATH = [cwd] diff --git a/bsp/mini2440/drivers/lcd.h b/bsp/mini2440/drivers/lcd.h deleted file mode 100644 index f733b5593c3a2817dd242188d512a3283bf721a0..0000000000000000000000000000000000000000 --- a/bsp/mini2440/drivers/lcd.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * File : lcd.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2008-03-29 Yi.Qiu - */ -#ifndef __LCD_H__ -#define __LCD_H__ - -#include - -void rt_hw_lcd_init(void); - -#endif diff --git a/bsp/mini2440/drivers/lcd_a70.c b/bsp/mini2440/drivers/lcd_a70.c index 02a89b9d4779647fd138e9bda99d0b2c7e073eda..7ebcf6a047855777b846d23a158497ec7976cbee 100644 --- a/bsp/mini2440/drivers/lcd_a70.c +++ b/bsp/mini2440/drivers/lcd_a70.c @@ -15,7 +15,6 @@ #include #include -#include "lcd.h" /* LCD driver for A7' */ #define LCD_WIDTH 800 @@ -223,10 +222,11 @@ static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) return RT_EOK; } -void rt_hw_lcd_init(void) +int rt_hw_lcd_init(void) { rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + if (lcd == RT_NULL) + return -RT_ERROR; /* no memory yet */ _lcd_info.bits_per_pixel = 16; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; @@ -246,3 +246,4 @@ void rt_hw_lcd_init(void) rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } +INIT_BOARD_EXPORT(rt_hw_lcd_init); diff --git a/bsp/mini2440/drivers/lcd_n35.c b/bsp/mini2440/drivers/lcd_n35.c index bcd3b85b8aff27f28898814b1ee06a5d2bac01f5..57d792ea392ea4313fe746c7286893b67a59834b 100644 --- a/bsp/mini2440/drivers/lcd_n35.c +++ b/bsp/mini2440/drivers/lcd_n35.c @@ -15,7 +15,6 @@ #include #include -#include "lcd.h" /* LCD driver for N3'5 */ #define LCD_WIDTH 240 @@ -224,10 +223,11 @@ static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) return RT_EOK; } -void rt_hw_lcd_init(void) +int rt_hw_lcd_init(void) { rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + if (lcd == RT_NULL) + return -RT_ERROR; /* no memory yet */ _lcd_info.bits_per_pixel = 16; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; @@ -247,3 +247,4 @@ void rt_hw_lcd_init(void) rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } +INIT_BOARD_EXPORT(rt_hw_lcd_init); diff --git a/bsp/mini2440/drivers/lcd_t35.c b/bsp/mini2440/drivers/lcd_t35.c index ef424a7bf76c3aba458aa685689b615542a12311..fdcab887f56e3216fdfd6520ea1d790bbb81fde8 100644 --- a/bsp/mini2440/drivers/lcd_t35.c +++ b/bsp/mini2440/drivers/lcd_t35.c @@ -15,7 +15,6 @@ #include #include -#include "lcd.h" /* LCD driver for T3'5 */ #define LCD_WIDTH 240 @@ -225,10 +224,11 @@ static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) return RT_EOK; } -void rt_hw_lcd_init(void) +int rt_hw_lcd_init(void) { rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + if (lcd == RT_NULL) + return -RT_ERROR; /* no memory yet */ _lcd_info.bits_per_pixel = 16; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; @@ -248,3 +248,4 @@ void rt_hw_lcd_init(void) rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } +INIT_BOARD_EXPORT(rt_hw_lcd_init); diff --git a/bsp/mini2440/drivers/lcd_t43.c b/bsp/mini2440/drivers/lcd_t43.c new file mode 100644 index 0000000000000000000000000000000000000000..54abc12f3e2a6d396a7c3a708d5bf44d75fe2c6b --- /dev/null +++ b/bsp/mini2440/drivers/lcd_t43.c @@ -0,0 +1,249 @@ +/* + * File : lcd_t43.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2010, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2020-04-12 Jonne first version from 4.3 inch lcd(480x272) + */ + +#include +#include + +/* LCD driver for N3'5 */ +#define LCD_WIDTH 480 +#define LCD_HEIGHT 272 +#define LCD_PIXCLOCK 4 + +#define LCD_RIGHT_MARGIN 2 +#define LCD_LEFT_MARGIN 2 +#define LCD_HSYNC_LEN 41 + +#define LCD_UPPER_MARGIN 2 +#define LCD_LOWER_MARGIN 2 +#define LCD_VSYNC_LEN 10 + +#define LCD_XSIZE LCD_WIDTH +#define LCD_YSIZE LCD_HEIGHT +#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 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 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_STN1BPP (0<<1) +#define S3C2410_LCDCON1_STN2GREY (1<<1) +#define S3C2410_LCDCON1_STN4GREY (2<<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_TFT16BPP (12<<1) +#define S3C2410_LCDCON1_TFT24BPP (13<<1) + +#define S3C2410_LCDCON1_ENVID (1) + +#define S3C2410_LCDCON1_MODEMASK 0x1E + +#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_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_HOZVAL(x) ((x) << 8) +#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_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_INVVLINE (1<<9) +#define S3C2410_LCDCON5_INVVFRAME (1<<8) +#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) + +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]; +static struct rt_device_graphic_info _lcd_info; + +static void lcd_power_enable(int invpwren, int pwren) +{ + //GPG4 is setted as LCD_PWREN + GPGUP = GPGUP | (1<<4); // Pull-up disable + GPGCON = GPGCON | (3<<8); //GPG4=LCD_PWREN + + //Enable LCD POWER ENABLE Function + LCDCON5 = LCDCON5&(~(1<<3))|(pwren<<3); // PWREN + LCDCON5 = LCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN +} + +static void lcd_envid_on_off(int onoff) +{ + 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) ; + GPBDAT &= ~(1<<1); + return; + } + GPBCON = GPBCON & (~(3<<2)) | (2<<2) ; + + if( HiRatio > 100 ) HiRatio = 100 ; + + TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1 + + 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 + + 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) ; +} + +/* RT-Thread Device Interface */ +static rt_err_t rt_lcd_init (rt_device_t dev) +{ + GPB1_TO_OUT(); + GPB1_TO_1(); + + GPCUP = 0x00000000; + GPCCON = 0xaaaa02a9; + + GPDUP = 0x00000000; + GPDCON = 0xaaaaaaaa; + +#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 - 1) << 24) | ((LCD_HEIGHT - 1) << 14) | ((LCD_LOWER_MARGIN - 1) << 6) | ((LCD_VSYNC_LEN - 1) << 0); + LCDCON3 = ((LCD_RIGHT_MARGIN - 1) << 19) | ((LCD_WIDTH - 1) << 8) | ((LCD_LEFT_MARGIN - 1) << 0); + LCDCON4 = (13 << 8) | ((LCD_HSYNC_LEN - 1) << 0); +#if !defined(LCD_CON5) + #define LCD_CON5 ((1<<11) | (0<<10) | (1<<9) | (1<<8) | (1<<0)) +#endif + 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; + + LCDINTMSK |= (3); + LPCSEL &= (~7) ; + TPAL=0; + + LcdBkLtSet(70) ; + lcd_power_enable(0, 1); + lcd_envid_on_off(1); + + 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; + } + + return RT_EOK; +} + +int rt_hw_lcd_init(void) +{ + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); + if (lcd == RT_NULL) + return -RT_ERROR; /* 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; + + /* 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); +} + +INIT_BOARD_EXPORT(rt_hw_lcd_init); diff --git a/bsp/mini2440/drivers/lcd_x35.c b/bsp/mini2440/drivers/lcd_x35.c index 679d433f9bbdda10d9dd86ada8a3f04a807440f0..e62590513073828b6dc17b364505a537c2b96374 100644 --- a/bsp/mini2440/drivers/lcd_x35.c +++ b/bsp/mini2440/drivers/lcd_x35.c @@ -17,7 +17,6 @@ #include #include -#include "lcd.h" /* LCD driver for X3'5 */ #define LCD_WIDTH 240 // xres @@ -230,10 +229,11 @@ static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args) return RT_EOK; } -void rt_hw_lcd_init(void) +int rt_hw_lcd_init(void) { rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); - if (lcd == RT_NULL) return; /* no memory yet */ + if (lcd == RT_NULL) + return -RT_ERROR; /* no memory yet */ _lcd_info.bits_per_pixel = 16; _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; @@ -253,3 +253,4 @@ void rt_hw_lcd_init(void) rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } +INIT_BOARD_EXPORT(rt_hw_lcd_init); diff --git a/bsp/mini2440/drivers/s3cmci.c b/bsp/mini2440/drivers/s3cmci.c new file mode 100644 index 0000000000000000000000000000000000000000..2333c74495325b8c38bbb775e1abbd9fcbd4ab19 --- /dev/null +++ b/bsp/mini2440/drivers/s3cmci.c @@ -0,0 +1,332 @@ +/* + * File : s3cmci.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2010, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2020-04-15 Jonne first version for s3c2440 mmc controller + */ + +#include +#include +#include +#include +#include + +#define S3C_PCLK 50000000 + + +static void s3c_mmc_set_clk(struct rt_mmcsd_host *host, rt_uint32_t clock) +{ + rt_uint32_t prescale; + rt_uint32_t realClk; + + for(prescale = 0; prescale < 256; ++prescale) + { + realClk = S3C_PCLK / (1 + prescale); + if(realClk <= clock) + { + break; + } + } + + SDIPRE = prescale; + host->io_cfg.clock = realClk; +} + +static rt_uint32_t s3c_mmc_send_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_cmd *cmd) +{ + rt_uint32_t ccon; + rt_uint32_t cmdSta; + + SDICARG = cmd->arg; + + ccon = cmd->cmd_code & 0x3f; + ccon |= (0 << 7) | (1 << 6); /* two start bits*/ + ccon |= (1 << 8);/* command start*/ + + if(cmd->flags & 0xF) + { + // Need response + ccon |= (1 << 9); + } + + if((cmd->flags & 0xF) == RESP_R2) + { + // R2 need 136bit response + ccon |= (1 << 10); + } + + SDICCON = ccon; /* start cmd */ + + if(cmd->flags & 0xF) + { + cmdSta = SDICSTA; + while((cmdSta & 0x200) != 0x200 && (cmdSta & 0x400) != 0x400) + { + cmdSta = SDICSTA; + } + + if((cmdSta & 0x1000) == 0x1000 && (cmd->flags & 0xF) != RESP_R3 && (cmd->flags & 0xF) != RESP_R4) + { + // crc error, but R3 R4 ignore it + SDICSTA = cmdSta; + return -RT_ERROR; + } + + if((cmdSta & 0xF00) != 0xa00) + { + SDICSTA = cmdSta; + return -RT_ERROR; + } + + cmd->resp[0] = SDIRSP0; + if((cmd->flags & 0xF) == RESP_R2) + { + cmd->resp[1] = SDIRSP1; + cmd->resp[2] = SDIRSP2; + cmd->resp[3] = SDIRSP3; + } + } + else + { + cmdSta = SDICSTA; + while((cmdSta & 0x800) != 0x800) + { + cmdSta = SDICSTA; + } + } + + SDICSTA = cmdSta; // clear current status + + return RT_EOK; + +} + +static rt_uint32_t s3c_mmc_xfer_data(struct rt_mmcsd_data *data) +{ + rt_uint32_t status; + rt_uint32_t xfer_size; + rt_uint32_t handled_size = 0; + rt_uint32_t *pBuf = RT_NULL; + + + if(data == RT_NULL) + { + return -RT_ERROR; + } + + xfer_size = data->blks * data->blksize; + + pBuf = data->buf; + if(data->flags & DATA_DIR_READ) + { + while(handled_size < xfer_size) + { + if ((SDIDSTA & 0x20) == 0x20) + { + SDIDSTA = (0x1 << 0x5); + break; + } + + status = SDIFSTA; + if ((status & 0x1000) == 0x1000) + { + *pBuf++ = SDIDAT; + handled_size += 4; + } + } + } + else + { + while(handled_size < xfer_size) + { + status = SDIFSTA; + if ((status & 0x2000) == 0x2000) + { + SDIDAT = *pBuf++; + handled_size += 4; + } + } + } + + // wait for end + status = SDIDSTA; + while((status & 0x30) == 0) + { + status = SDIDSTA; + } + SDIDSTA = status; + + if ((status & 0xfc) != 0x10) + { + return -RT_ERROR; + } + + SDIDCON = SDIDCON & ~(7<<12); + SDIFSTA = SDIFSTA & 0x200; + SDIDSTA = 0x10; + + return RT_EOK; +} +static void mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req) +{ + rt_uint32_t ret; + struct rt_mmcsd_cmd *cmd; + struct rt_mmcsd_data *data; + rt_uint32_t val; + rt_uint32_t tryCnt = 0; + + if(req->cmd == RT_NULL) + { + goto out; + } + cmd = req->cmd; + + /* prepare for data transfer*/ + if(req->data != RT_NULL) + { + SDIFSTA = SDIFSTA | (1<<16); // reset fifo + + while(SDIDSTA & 0x03) + { + if(tryCnt++ > 500) + { + break; + SDIDSTA = SDIDSTA; + } + } + + data = req->data; + + if((data->blksize & 0x3) != 0) + { + goto out; + } + + val = (2 << 22) //word transfer + | (1 << 20) // transmet after response + | (1 << 19) // reciveve after command sent + | (1 << 17) // block data transfer + | (1 << 14); // data start + + if(host->io_cfg.bus_width == MMCSD_BUS_WIDTH_4) + { + val |= (1 << 16); // wide bus mode(4bit data) + } + + if(data->flags & DATA_DIR_READ) + { + // for data read + val |= (2 << 12); + } + else + { + val |= (3 << 12); + } + + val |= (data->blks & 0xFFF); + + SDIDCON = val; + + SDIBSIZE = data->blksize; + SDIDTIMER = 0x7fffff; + } + + ret = s3c_mmc_send_cmd(host,req->cmd); + if(ret != RT_EOK) { + cmd->err = ret; + goto out; + } + + if(req->data != RT_NULL) + { + /*do transfer data*/ + ret = s3c_mmc_xfer_data(data); + if(ret != RT_EOK) + { + data->err = ret; + goto out; + } + } + +out: + mmcsd_req_complete(host); +} +static void mmc_set_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg) +{ + switch (io_cfg->power_mode) { + case MMCSD_POWER_ON: + case MMCSD_POWER_UP: + /* Enable PCLK into SDI Block */ + CLKCON |= 1 << 9; + + /* Setup GPIO as SD and SDCMD, SDDAT[3:0] Pull up En */ + GPEUP = GPEUP & (~(0x3f << 5)) | (0x01 << 5); + GPECON = GPECON & (~(0xfff << 10)) | (0xaaa << 10); + break; + + case MMCSD_POWER_OFF: + default: + break; + } + + s3c_mmc_set_clk(host, io_cfg->clock); + + SDICON = 1; +} + +static rt_int32_t mmc_get_card_status(struct rt_mmcsd_host *host) +{ + return RT_EOK; +} +static void mmc_enable_sdio_irq(struct rt_mmcsd_host *host, rt_int32_t en) +{ +} + +static const struct rt_mmcsd_host_ops ops = +{ + mmc_request, + mmc_set_iocfg, + mmc_get_card_status, + mmc_enable_sdio_irq +}; + +int s3c_sdio_init(void) +{ + struct rt_mmcsd_host * host = RT_NULL; + + + host = mmcsd_alloc_host(); + if (!host) + { + goto err; + } + + host->ops = &ops; + host->freq_min = 300000; + host->freq_max = 50000000; + host->valid_ocr = VDD_32_33 | VDD_33_34; + host->flags = MMCSD_MUTBLKWRITE | MMCSD_SUP_HIGHSPEED | MMCSD_SUP_SDIO_IRQ | MMCSD_BUSWIDTH_4; + host->max_seg_size = 2048; + host->max_dma_segs = 10; + host->max_blk_size = 512; + host->max_blk_count = 4096; + + + mmcsd_change(host); + + return RT_EOK; + +err: + if(host) rt_free(host); + + return -RT_EIO; +} + +INIT_DEVICE_EXPORT(s3c_sdio_init); diff --git a/bsp/mini2440/drivers/sdcard.c b/bsp/mini2440/drivers/sdcard.c deleted file mode 100644 index 9815770babc55cc402f3edbb7ed896a6564e8fa0..0000000000000000000000000000000000000000 --- a/bsp/mini2440/drivers/sdcard.c +++ /dev/null @@ -1,651 +0,0 @@ -/* - * File : sd.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, 2007, RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2007-12-02 Yi.Qiu the first version - * 2010-01-01 Bernard Modify for mini2440 - * 2012-12-15 amr168 support SDHC - * 2017-11-20 kuangdazzidd add csd cmd support - */ - -#include "sdcard.h" -#include "rtdef.h" - -extern rt_uint32_t PCLK; -volatile rt_uint32_t rd_cnt; -volatile rt_uint32_t wt_cnt; -volatile rt_int32_t RCA; -volatile rt_int32_t sd_type; - -struct sd_csd { - rt_uint16_t bsize; - rt_uint32_t nblks; -}g_sd_csd; - -static void sd_delay(rt_uint32_t ms) -{ - ms *= 7326; - while(--ms); -} - -static int sd_cmd_end(int cmd, int be_resp) -{ - int finish0; - - if (!be_resp) - { - finish0 = SDICSTA; - - while ((finish0&0x800) != 0x800) - finish0 = SDICSTA; - - SDICSTA = finish0; - - return RT_EOK; - } - else - { - finish0 = SDICSTA; - - while (!(((finish0&0x200)==0x200) | ((finish0&0x400) == 0x400))) - finish0=SDICSTA; - - if (cmd == 1 || cmd == 41) - { - if ((finish0 & 0xf00) != 0xa00) - { - SDICSTA = finish0; - if ((finish0&0x400) == 0x400) - return RT_ERROR; - } - SDICSTA = finish0; - } - else - { - if ((finish0 & 0x1f00) != 0xa00) - { - /* rt_kprintf("CMD%d:SDICSTA=0x%x, SDIRSP0=0x%x\n", cmd, SDICSTA, SDIRSP0); */ - SDICSTA = finish0; - if ((finish0 & 0x400) == 0x400) - return RT_ERROR; - } - SDICSTA = finish0; - } - return RT_EOK; - } -} - -static int sd_data_end(void) -{ - int finish; - - finish = SDIDSTA; - - while (!(((finish & 0x10) == 0x10) | ((finish & 0x20) == 0x20))) - { - finish = SDIDSTA; - } - - if ((finish & 0xfc) != 0x10) - { - SDIDSTA = 0xec; - - return RT_ERROR; - } - - return RT_EOK; -} - -static void sd_cmd0(void) -{ - SDICARG = 0x0; - SDICCON = (1<<8) | 0x40; - - sd_cmd_end(0, 0); - SDICSTA = 0x800; /* Clear cmd_end(no rsp) */ -} - -static int sd_cmd55(void) -{ - SDICARG = RCA << 16; - SDICCON = (0x1 << 9) | (0x1 << 8) | 0x77; - - if (sd_cmd_end(55, 1) == RT_ERROR) - { - /* rt_kprintf("CMD55 error\n"); */ - return RT_ERROR; - } - - SDICSTA = 0xa00; - - - return RT_EOK; -} - -static int sd_cmd9(void *p_rsp) -{ -SDICARG = RCA << 16; -SDICCON = (1 << 10) | (1 << 9) | (0x1<<8) | (0x40 | 0x09); - -sd_cmd_end(9, 1); - - ((rt_uint32_t *)p_rsp)[0] = SDIRSP3; - ((rt_uint32_t *)p_rsp)[1] = SDIRSP2; - ((rt_uint32_t *)p_rsp)[2] = SDIRSP1; - ((rt_uint32_t *)p_rsp)[3] = SDIRSP0; - -return RT_EOK; -} - -static void sd_sel_desel(char sel_desel) -{ - if (sel_desel) - { -RECMDS7: - SDICARG = RCA << 16; - SDICCON = (0x1 << 9) | (0x1 << 8) | 0x47; - if (sd_cmd_end(7, 1) == RT_ERROR) - goto RECMDS7; - - SDICSTA = 0xa00; - - if (SDIRSP0 & 0x1e00 != 0x800) - goto RECMDS7; - } - else - { -RECMDD7: - SDICARG = 0 << 16; - SDICCON = (0x1 << 8) | 0x47; - - if (sd_cmd_end(7, 0) == RT_ERROR) - goto RECMDD7; - SDICSTA = 0x800; - } -} - -static void sd_setbus(void) -{ - do - { - sd_cmd55(); - - SDICARG = 1 << 1; /* 4bit bus */ - SDICCON = (0x1<<9) | (0x1<<8) | 0x46; /* sht_resp, wait_resp, start, CMD55 */ - }while (sd_cmd_end(6, 1) == RT_ERROR); - - SDICSTA=0xa00; /* Clear cmd_end(with rsp) */ -} - - -static rt_uint32_t bits_str (rt_uint32_t *str, rt_uint32_t start, rt_uint8_t len) -{ - rt_uint32_t mask; - rt_uint32_t index; - rt_uint8_t shift; - rt_uint32_t value; - - mask = (int)((len < 32) ? (1 << len) : 0) - 1; - index = start / 32; - shift = start & 31; - value = str[index] >> shift; - - if ((len + shift) > 32) { - value |= str[index + 1] << (32 - shift); - } - value &= mask; - return value; -} - - -static int sd_decode_csd (rt_uint32_t *p_csd) -{ - rt_uint32_t e, m, r; - rt_uint8_t structure; - - structure = bits_str(p_csd, 126, 2); - - switch (structure) { - case 0: - m = bits_str(p_csd, 99, 4); - e = bits_str(p_csd, 96, 3); - g_sd_csd.bsize = 512; - m = bits_str(p_csd, 62, 12); - e = bits_str(p_csd, 47, 3); - r = bits_str(p_csd, 80, 4); - g_sd_csd.nblks = ((1 + m) << (e + r - 7)); - break; - - case 1: - m = bits_str(p_csd, 99, 4); - e = bits_str(p_csd, 96, 3); - g_sd_csd.bsize = 512; - m = bits_str(p_csd, 48, 22); - g_sd_csd.nblks = (1 + m) << 10; - break; - - default: - return RT_ERROR; - } - return RT_EOK; -} - - -static int sd_send_csd(rt_uint32_t *p_csd) -{ - int ret; - rt_uint32_t rsp[4]; - - ret = sd_cmd9((void*)&rsp); - - if (ret != 0) { - return ret; - } - - rt_memcpy((void*)p_csd, (void*)rsp, 16); - return RT_EOK; -} - -static int sd_ocr(void) -{ - int i, ver=0; - - /* Negotiate operating condition for SD, it makes card ready state */ - for (i = 0; i < 50; i ++) - { - sd_cmd55(); - - SDICARG = 0x40ff8000; /* HCS=1, compatible v1.x and v2.0 */ - SDICCON = (0x1<<9) | (0x1<<8) | 0x69; - - /* if using real board, should replace code here. need to modify qemu in near future*/ - /* Check end of ACMD41 */ - if (sd_cmd_end(41, 1) == RT_EOK) - { - if (SDIRSP0 == 0x80ff8000) - { - ver = 1; /* SD V1.x, CCS=0 */ - break; - } - else if (SDIRSP0 == 0xc0ff8000) - { - ver = 2; /* SD V2.0, CCS=1 */ - break; - } - } - - sd_delay(200); - } - SDICSTA = 0xa00; - - return ver; -} - -rt_err_t sd_cmd8(void) -{ - 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_ERROR; -} - -static rt_uint8_t sd_init(void) -{ - //-- SD controller & card initialize - int i; - rt_uint32_t csd[4]; - /* Important notice for MMC test condition */ - /* Cmd & Data lines must be enabled by pull up resister */ - SDIPRE = PCLK / (INICLK) - 1; - SDICON = (0<<4) | 1; // Type A, clk enable - SDIFSTA = SDIFSTA | (1<<16); - SDIBSIZE = 0x200; /* 512byte per one block */ - SDIDTIMER = 0x7fffff; /* timeout count */ - - /* Wait 74SDCLK for MMC card */ - for (i = 0; i < 0x1000; i ++); - - sd_cmd0(); - sd_cmd8(); /* Must be use it, Host shall supports high capacity */ - - /* Check SD card OCR */ - sd_type = sd_ocr(); - if (sd_type > 0) - { - rt_kprintf("In SD ready\n"); - } - else - { - rt_kprintf("Initialize fail\nNo Card assertion\n"); - - return RT_ERROR; - } - -RECMD2: - SDICARG = 0x0; - SDICCON = (0x1<<10)|(0x1<<9)|(0x1<<8)|0x42; /* lng_resp, wait_resp, start, CMD2 */ - if (sd_cmd_end(2, 1) == RT_ERROR) - goto RECMD2; - - SDICSTA = 0xa00; /* Clear cmd_end(with rsp) */ - -RECMD3: - SDICARG = 0<<16; /* CMD3(MMC:Set RCA, SD:Ask RCA-->SBZ) */ - SDICCON = (0x1<<9)|(0x1<<8)|0x43; /* sht_resp, wait_resp, start, CMD3 */ - if (sd_cmd_end(3, 1) == RT_ERROR) - goto RECMD3; - SDICSTA=0xa00; /* Clear cmd_end(with rsp) */ - - sd_send_csd(csd); - sd_decode_csd(csd); - - RCA = (SDIRSP0 & 0xffff0000) >> 16; - SDIPRE = PCLK / (SDCLK) - 1; /* Normal clock=25MHz */ - if (SDIRSP0 & 0x1e00 != 0x600) - goto RECMD3; - - sd_sel_desel(1); - sd_delay(200); - sd_setbus(); - - return RT_EOK; -} - -static rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t *buf) -{ - rt_uint32_t status, tmp; - - rd_cnt = 0; - SDIFSTA = SDIFSTA | (1<<16); - - SDIDCON = (2 << 22) | (1 << 19) | (1 << 17) | (1 << 16) | (1 << 14) | (2 << 12) | (1 << 0); - SDICARG = address; - -RERDCMD: - SDICCON = (0x1 << 9 ) | (0x1 << 8) | 0x51; - if (sd_cmd_end(17, 1) == RT_ERROR) - { - rt_kprintf("Read CMD Error\n"); - goto RERDCMD; - } - - SDICSTA = 0xa00; - - while (rd_cnt < 128) - { - if ((SDIDSTA & 0x20) == 0x20) - { - SDIDSTA = (0x1 << 0x5); - break; - } - status = SDIFSTA; - if ((status & 0x1000) == 0x1000) - { - tmp = SDIDAT; - rt_memcpy(buf, &tmp, sizeof(rt_uint32_t)); - rd_cnt ++; - buf += 4; - } - } - if (sd_data_end() == RT_ERROR) - { - rt_kprintf("Dat error\n"); - - return RT_ERROR; - } - - SDIDCON = SDIDCON &~ (7<<12); - SDIFSTA = SDIFSTA & 0x200; - SDIDSTA = 0x10; - - return RT_EOK; -} - -static rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t *buf) -{ - rt_uint32_t status, tmp; - - wt_cnt = 0; - SDIFSTA = SDIFSTA | (1 << 16); - - SDIDCON = (2 << 22) | (1 << 20) | (1 << 17) | (1 << 16) | (1 << 14) | (3 << 12) | (1 << 0); - SDICARG = address; - -REWTCMD: - SDICCON = (0x1 << 9) | (0x1 << 8) |0x58; - - if (sd_cmd_end(24, 1) == RT_ERROR) - goto REWTCMD; - - SDICSTA = 0xa00; - - while (wt_cnt < 128) - { - status = SDIFSTA; - if ((status & 0x2000) == 0x2000) - { - rt_memcpy(&tmp, buf, sizeof(rt_uint32_t)); - SDIDAT = tmp; - wt_cnt ++; - buf += 4; - } - } - if (sd_data_end() == RT_ERROR) - { - rt_kprintf("Data Error\n"); - - return RT_ERROR; - } - SDIDCON = SDIDCON &~ (7<<12); - SDIDSTA = 0x10; - - return RT_EOK; -} - -#ifdef RT_USING_DFS -/* RT-Thread Device Driver Interface */ -#include - -#include - -struct rt_device sdcard_device[4]; -struct dfs_partition part[4]; - -static rt_err_t rt_sdcard_init(rt_device_t dev) -{ - return RT_EOK; -} - -static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag) -{ - return RT_EOK; -} - -static rt_err_t rt_sdcard_close(rt_device_t dev) -{ - return RT_EOK; -} - -static rt_err_t rt_sdcard_control(rt_device_t dev, int cmd, void *args) -{ -struct rt_device_blk_geometry *p_geometry = (struct rt_device_blk_geometry *)args; -p_geometry->block_size = g_sd_csd.bsize; -p_geometry->sector_count = g_sd_csd.nblks; -p_geometry->bytes_per_sector = 512; - return RT_EOK; -} - -static rt_size_t rt_sdcard_read(rt_device_t dev, - rt_off_t pos, - void *buffer, - rt_size_t size) -{ - int i, addr; - struct dfs_partition *part = (struct dfs_partition *)dev->user_data; - - if (dev == RT_NULL) - { - rt_set_errno(-EINVAL); - - return 0; - } - - /* read all sectors */ - for (i = 0; i < size; i ++) - { - rt_sem_take(part->lock, RT_WAITING_FOREVER); - if (sd_type == 1) - addr = (part->offset + i + pos)*SECTOR_SIZE; - else - addr = (part->offset + i + pos); - sd_readblock(addr, (rt_uint8_t *)((rt_uint8_t *)buffer + i * SECTOR_SIZE)); - rt_sem_release(part->lock); - } - - /* the length of reading must align to SECTOR SIZE */ - return size; -} - -static rt_size_t rt_sdcard_write(rt_device_t dev, - rt_off_t pos, - const void *buffer, - rt_size_t size) -{ - int i, addr; - struct dfs_partition *part = (struct dfs_partition *)dev->user_data; - - if (dev == RT_NULL) - { - rt_set_errno(-EINVAL); - - return 0; - } - - /* read all sectors */ - for (i = 0; i < size; i++) - { - rt_sem_take(part->lock, RT_WAITING_FOREVER); - if (sd_type == 1) - addr = (part->offset + i + pos)*SECTOR_SIZE; - else - addr = (part->offset + i + pos); - sd_writeblock(addr, (rt_uint8_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE)); - rt_sem_release(part->lock); - } - - /* the length of reading must align to SECTOR SIZE */ - return size; -} - -int rt_hw_sdcard_init(void) -{ - rt_uint8_t i, status; - rt_uint8_t *sector; - char dname[4]; - char sname[8]; - - /* Enable PCLK into SDI Block */ - CLKCON |= 1 << 9; - - /* Setup GPIO as SD and SDCMD, SDDAT[3:0] Pull up En */ - GPEUP = GPEUP & (~(0x3f << 5)) | (0x01 << 5); - GPECON = GPECON & (~(0xfff << 10)) | (0xaaa << 10); - - RCA = 0; - - if (sd_init() == RT_EOK) - { - /* get the first sector to read partition table */ - sector = (rt_uint8_t*) rt_malloc (512); - if (sector == RT_NULL) - { - rt_kprintf("allocate partition sector buffer failed\n"); - - return -RT_ERROR; - } - status = sd_readblock(0, sector); - if (status == RT_EOK) - { - for (i = 0; i < 4; i ++) - { - /* get the first partition */ - status = dfs_filesystem_get_partition(&part[i], sector, i); - if (status == RT_EOK) - { - rt_snprintf(dname, 4, "sd%d", i); - rt_snprintf(sname, 8, "sem_sd%d", i); - part[i].lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO); - - /* register sdcard device */ - sdcard_device[i].type = RT_Device_Class_Block; - sdcard_device[i].init = rt_sdcard_init; - sdcard_device[i].open = rt_sdcard_open; - sdcard_device[i].close = rt_sdcard_close; - sdcard_device[i].read = rt_sdcard_read; - sdcard_device[i].write = rt_sdcard_write; - sdcard_device[i].control = rt_sdcard_control; - sdcard_device[i].user_data = &part[i]; - - rt_device_register(&sdcard_device[i], dname, - RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); - } - else - { - if (i == 0) - { - /* there is no partition table */ - part[0].offset = 0; - part[0].size = 0; - part[0].lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO); - - /* register sdcard device */ - sdcard_device[0].type = RT_Device_Class_Block; - sdcard_device[0].init = rt_sdcard_init; - sdcard_device[0].open = rt_sdcard_open; - sdcard_device[0].close = rt_sdcard_close; - sdcard_device[0].read = rt_sdcard_read; - sdcard_device[0].write = rt_sdcard_write; - sdcard_device[0].control = rt_sdcard_control; - sdcard_device[0].user_data = &part[0]; - - rt_device_register(&sdcard_device[0], "sd0", - RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); - - break; - } - } - } - } - else - { - rt_kprintf("read sdcard first sector failed\n"); - } - - /* release sector buffer */ - rt_free(sector); - - return -RT_ERROR; - } - else - { - rt_kprintf("sdcard init failed\n"); - } - - return RT_EOK; -} - -INIT_BOARD_EXPORT(rt_hw_sdcard_init); -#endif diff --git a/bsp/mini2440/drivers/sdcard.h b/bsp/mini2440/drivers/sdcard.h deleted file mode 100644 index f9aa52e818c75ff706a8291b08b2b88cd4b46149..0000000000000000000000000000000000000000 --- a/bsp/mini2440/drivers/sdcard.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __SDCARD_H -#define __SDCARD_H - -#include - -#define INICLK 300000 -#define SDCLK 24000000 //PCLK=49.392MHz -#define MMCCLK 15000000 //PCLK=49.392MHz - -#endif - diff --git a/bsp/mini2440/drivers/touch.c b/bsp/mini2440/drivers/touch.c index e584c379e33b6d4b7a8bd79a83c26e986990ffbe..b2d09ff7a52dea4d0b927138ba8afb0f39fddb0e 100644 --- a/bsp/mini2440/drivers/touch.c +++ b/bsp/mini2440/drivers/touch.c @@ -16,13 +16,14 @@ #include #include -#ifdef RT_USING_RTGUI +#ifdef PKG_USING_GUIENGINE #include #include #include #endif -#include "lcd.h" +#define TOUCH_SWAP_XY + #include "touch.h" /* ADCCON Register Bits */ @@ -108,7 +109,7 @@ struct rtgui_touch_device }; static struct rtgui_touch_device *touch = RT_NULL; -#ifdef RT_USING_RTGUI +#ifdef PKG_USING_GUIENGINE static void report_touch_input(int updown) { struct rtgui_event_mouse emouse; @@ -125,6 +126,12 @@ static void report_touch_input(int updown) ts.xp = ts.xp / ts.count; ts.yp = ts.yp / ts.count;; + #ifdef TOUCH_SWAP_XY + ts.xp = ts.xp + ts.yp; + ts.yp = ts.xp - ts.yp; + ts.xp = ts.xp - ts.yp; + #endif + if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL)) { touch->x = ts.xp; @@ -446,7 +453,7 @@ static rt_err_t rtgui_touch_control(rt_device_t dev, int cmd, void *args) return RT_EOK; } -void rtgui_touch_hw_init(void) +int rtgui_touch_hw_init(void) { rt_err_t result = RT_FALSE; rt_device_t device = RT_NULL; @@ -454,7 +461,7 @@ void rtgui_touch_hw_init(void) touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device)); if (touch == RT_NULL) - return; /* no memory yet */ + return -RT_ERROR; /* no memory yet */ /* clear device structure */ rt_memset(&(touch->parent), 0, sizeof(struct rt_device)); @@ -473,17 +480,19 @@ void rtgui_touch_hw_init(void) touch->parent.user_data = RT_NULL; device = rt_device_find("lcd"); - if (device == RT_NULL) - return; /* no this device */ + if (device == RT_NULL) + { + rt_kprintf("No lcd found\n"); + return -RT_ERROR; /* no this device */ + } /* get graphic device info */ result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); if (result != RT_EOK) { - /* get device information failed */ - - return; + rt_kprintf("Get graphic device info failed\n"); + return -RT_ERROR; } touch->width = info.width; @@ -495,4 +504,8 @@ void rtgui_touch_hw_init(void) /* register touch device to RT-Thread */ rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR); + + return RT_EOK; } + +INIT_PREV_EXPORT(rtgui_touch_hw_init); diff --git a/bsp/mini2440/drivers/touch.h b/bsp/mini2440/drivers/touch.h index 854f2747828820ec2b5395ab2b45322616dec4db..c0e1238148d16ebd1014b9d678a81b7d9135cf28 100644 --- a/bsp/mini2440/drivers/touch.h +++ b/bsp/mini2440/drivers/touch.h @@ -26,7 +26,7 @@ typedef void (*rt_touch_calibration_func_t)(rt_uint16_t x, rt_uint16_t y); typedef void (*rt_touch_eventpost_func_t)(void *, struct rt_touch_event *); -void rtgui_touch_hw_init(void); +int rtgui_touch_hw_init(void); #endif diff --git a/bsp/mini2440/rtconfig.h b/bsp/mini2440/rtconfig.h index 5d65b461482987dd92d2885cb669a3b7d58ec069..37c215bdd0e99dc3aa29c693d220178414888747 100644 --- a/bsp/mini2440/rtconfig.h +++ b/bsp/mini2440/rtconfig.h @@ -107,6 +107,12 @@ #define RT_SERIAL_USING_DMA #define RT_SERIAL_RB_BUFSZ 64 #define RT_USING_PIN +#define RT_USING_SDIO +#define RT_SDIO_STACK_SIZE 512 +#define RT_SDIO_THREAD_PRIORITY 15 +#define RT_MMCSD_STACK_SIZE 1024 +#define RT_MMCSD_THREAD_PREORITY 22 +#define RT_MMCSD_MAX_PARTITION 16 /* Using USB */ diff --git a/bsp/mini2440/rtconfig.py b/bsp/mini2440/rtconfig.py index 106597711a985af61bb3563e7fee28aed59f5880..f8332f1e6cd959cc3ba143cc14545196a46cd5f2 100644 --- a/bsp/mini2440/rtconfig.py +++ b/bsp/mini2440/rtconfig.py @@ -1,9 +1,5 @@ import os -# panel options -# 'PNL_A70','PNL_N35', 'PNL_T35' , 'PNL_X35' -RT_USING_LCD_TYPE = 'PNL_T35' - # toolchains options ARCH = 'arm' CPU = 's3c24x0'