@@ -0,0 +1,19 | |||||
|
1 | ||||
|
2 | #include <stdio.h> | |||
|
3 | #include <fat32.h> | |||
|
4 | #include <ucdirent.h> | |||
|
5 | ||||
|
6 | void printRootClustersChain(FAT32fs* sdcard2FAT32part) | |||
|
7 | { | |||
|
8 | ucdirent root; | |||
|
9 | uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba; | |||
|
10 | sector_lba=tmp; | |||
|
11 | do | |||
|
12 | { | |||
|
13 | printf("Sector @0x%x\n",tmp); | |||
|
14 | //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1; | |||
|
15 | sector_lba=tmp; | |||
|
16 | res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp); | |||
|
17 | }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect)); | |||
|
18 | ||||
|
19 | } |
@@ -1,543 +1,541 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include "bsp.h" |
|
22 | #include "bsp.h" | |
23 | #include <streamdevices.h> |
|
23 | #include <streamdevices.h> | |
24 | #include <malloc.h> |
|
24 | #include <malloc.h> | |
25 | #include <gpio.h> |
|
25 | #include <gpio.h> | |
26 | #include <uart.h> |
|
26 | #include <uart.h> | |
27 | #include <stdio.h> |
|
27 | #include <stdio.h> | |
28 | #include <stm32f4xx_gpio.h> |
|
28 | #include <stm32f4xx_gpio.h> | |
29 | #include <stm32f4xx_fsmc.h> |
|
29 | #include <stm32f4xx_fsmc.h> | |
30 | #include <i2c.h> |
|
30 | #include <i2c.h> | |
31 | #include <core.h> |
|
31 | #include <core.h> | |
32 | #include <terminal.h> |
|
32 | #include <terminal.h> | |
33 |
|
33 | |||
34 | uint32_t OSC0 =8000000; |
|
34 | uint32_t OSC0 =8000000; | |
35 | uint32_t INTOSC =16000000; |
|
35 | uint32_t INTOSC =16000000; | |
36 | uint32_t RTCOSC =32768; |
|
36 | uint32_t RTCOSC =32768; | |
37 | uint32_t currentCpuFreq=0; |
|
37 | uint32_t currentCpuFreq=0; | |
38 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
38 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
39 |
|
39 | |||
40 | LCD_IF_t lcdIF0={ |
|
40 | LCD_IF_t lcdIF0={ | |
41 | .init = &bsp_FSMC_init, |
|
41 | .init = &bsp_FSMC_init, | |
42 | .writereg = &bsp_lcd0_write_reg, |
|
42 | .writereg = &bsp_lcd0_write_reg, | |
43 | .readreg = &bsp_lcd0_read_reg, |
|
43 | .readreg = &bsp_lcd0_read_reg, | |
44 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
44 | .writeGRAM = &bsp_lcd0_writeGRAM, | |
45 | .readGRAM = &bsp_lcd0_readGRAM |
|
45 | .readGRAM = &bsp_lcd0_readGRAM | |
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | LCD_t lcd0={ |
|
48 | LCD_t lcd0={ | |
49 | .interface = &lcdIF0, |
|
49 | .interface = &lcdIF0, | |
50 | .init = &ili9328init, |
|
50 | .init = &ili9328init, | |
51 | .paint = &ili9328paint, |
|
51 | .paint = &ili9328paint, | |
52 | .paintText = &ili9328paintText, |
|
52 | .paintText = &ili9328paintText, | |
53 | .paintFilRect = &ili9328paintFilRect, |
|
53 | .paintFilRect = &ili9328paintFilRect, | |
54 | .getPix = &ili9328getPix, |
|
54 | .getPix = &ili9328getPix, | |
55 | .refreshenable = &ili9328refreshenable, |
|
55 | .refreshenable = &ili9328refreshenable, | |
56 | .width= 240, |
|
56 | .width= 240, | |
57 | .height = 320 |
|
57 | .height = 320 | |
58 | }; |
|
58 | }; | |
59 |
|
59 | |||
60 | terminal_t terminal0; |
|
60 | terminal_t terminal0; | |
61 |
|
61 | |||
62 | volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; |
|
62 | volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; | |
|
63 | volatile int16_t* lcd0_CMD16=(volatile int16_t*)0x60000000; | |||
63 | volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; |
|
64 | volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; | |
|
65 | volatile int16_t* lcd0_DATA16=(volatile int16_t*)0x61FFFFF0; | |||
64 |
|
66 | |||
65 | float VREF0 =(float)3.3; |
|
67 | float VREF0 =(float)3.3; | |
66 | volatile vs10XXDev audioCodec0; |
|
68 | volatile vs10XXDev audioCodec0; | |
67 |
|
69 | |||
68 | sdcardDev sdcard2; |
|
70 | sdcardDev sdcard2; | |
69 | blkdevice sdcard2blkdev; |
|
71 | blkdevice sdcard2blkdev; | |
70 | dikpartition sdcard2Part1; |
|
72 | dikpartition sdcard2Part1; | |
71 | FAT32fs sdcard2FAT32part1; |
|
73 | FAT32fs sdcard2FAT32part1; | |
72 | dikpartition sdcard2Part2; |
|
74 | dikpartition sdcard2Part2; | |
73 | FAT32fs sdcard2FAT32part2; |
|
75 | FAT32fs sdcard2FAT32part2; | |
74 | dikpartition sdcard2Part3; |
|
76 | dikpartition sdcard2Part3; | |
75 | FAT32fs sdcard2FAT32part3; |
|
77 | FAT32fs sdcard2FAT32part3; | |
76 | dikpartition sdcard2Part4; |
|
78 | dikpartition sdcard2Part4; | |
77 | FAT32fs sdcard2FAT32part4; |
|
79 | FAT32fs sdcard2FAT32part4; | |
78 |
|
80 | |||
79 | int bsp_init() |
|
81 | int bsp_init() | |
80 | { |
|
82 | { | |
81 | int i=0; |
|
83 | int i=0; | |
82 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
84 | for(i=0;i<__MAX_OPENED_FILES__;i++) | |
83 | { |
|
85 | { | |
84 | __opnfiles__[i] = NULL; |
|
86 | __opnfiles__[i] = NULL; | |
85 | } |
|
87 | } | |
86 | bsp_GPIO_init(); |
|
88 | bsp_GPIO_init(); | |
87 | bsp_uart_init(); |
|
89 | bsp_uart_init(); | |
88 | bsp_iic_init(); |
|
90 | bsp_iic_init(); | |
89 | bsp_FSMC_init(); |
|
91 | bsp_FSMC_init(); | |
90 | bsp_GTerm_init(); |
|
92 | bsp_GTerm_init(); | |
91 | bsp_spi_init(); |
|
93 | bsp_spi_init(); | |
92 | bsp_SD_init(); |
|
94 | bsp_SD_init(); | |
93 | bsp_Audio_init(); |
|
95 | bsp_Audio_init(); | |
94 | printf("\r=====================\n\r"); |
|
96 | printf("\r=====================\n\r"); | |
95 | printf( "=====================\n\r"); |
|
97 | printf( "=====================\n\r"); | |
96 | printf(BSP); |
|
98 | printf(BSP); | |
97 | printf(" initialised\n\r"); |
|
99 | printf(" initialised\n\r"); | |
98 | printf( "=====================\n\r"); |
|
100 | printf( "=====================\n\r"); | |
99 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
101 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
100 | printf( "BIG ENDIAN MACHINE\n\r"); |
|
102 | printf( "BIG ENDIAN MACHINE\n\r"); | |
101 | #else |
|
103 | #else | |
102 | printf( "LITLE ENDIAN MACHINE\n\r"); |
|
104 | printf( "LITLE ENDIAN MACHINE\n\r"); | |
103 | #endif |
|
105 | #endif | |
104 | return 1; |
|
106 | return 1; | |
105 | } |
|
107 | } | |
106 |
|
108 | |||
107 | void bsp_GPIO_init() |
|
109 | void bsp_GPIO_init() | |
108 | { |
|
110 | { | |
109 | gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS}; |
|
111 | gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS}; | |
110 | for(int i=0;i<8;i++) |
|
112 | for(int i=0;i<8;i++) | |
111 | { |
|
113 | { | |
112 | gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]); |
|
114 | gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]); | |
113 | GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype; |
|
115 | GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype; | |
114 | gpiosetconfig(&GPIO_init); |
|
116 | gpiosetconfig(&GPIO_init); | |
115 | } |
|
117 | } | |
116 | gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3}; |
|
118 | gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3}; | |
117 | for(int i=0;i<3;i++) |
|
119 | for(int i=0;i<3;i++) | |
118 | { |
|
120 | { | |
119 | gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]); |
|
121 | gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]); | |
120 | GPIO_init |= gpiohighspeed | gpioindir; |
|
122 | GPIO_init |= gpiohighspeed | gpioindir; | |
121 | gpiosetconfig(&GPIO_init); |
|
123 | gpiosetconfig(&GPIO_init); | |
122 | } |
|
124 | } | |
123 | gpioclr(VS1053xRESET); |
|
125 | gpioclr(VS1053xRESET); | |
124 | gpioset(VS1053xCS); |
|
126 | gpioset(VS1053xCS); | |
125 | gpioset(VS1053xDCS); |
|
127 | gpioset(VS1053xDCS); | |
126 | gpioset(SDCARD2CS); |
|
128 | gpioset(SDCARD2CS); | |
127 | gpioclr(LCD_RESET); |
|
129 | gpioclr(LCD_RESET); | |
128 | gpioclr(LCD_BACKL); |
|
130 | gpioclr(LCD_BACKL); | |
129 | } |
|
131 | } | |
130 |
|
132 | |||
131 | void bsp_uart_init() |
|
133 | void bsp_uart_init() | |
132 | { |
|
134 | { | |
133 | // if(__opnfiles__[1]==NULL) |
|
135 | // if(__opnfiles__[1]==NULL) | |
134 | // { |
|
136 | // { | |
135 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
137 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
136 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
138 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
137 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
139 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
138 | // uartmkstreamdev(uart,fd1); |
|
140 | // uartmkstreamdev(uart,fd1); | |
139 | // __opnfiles__[1] = fd1; |
|
141 | // __opnfiles__[1] = fd1; | |
140 | // } |
|
142 | // } | |
141 | // else |
|
143 | // else | |
142 | // { |
|
144 | // { | |
143 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
145 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
144 | // } |
|
146 | // } | |
145 | } |
|
147 | } | |
146 |
|
148 | |||
147 | /* |
|
149 | /* | |
148 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
150 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 | |
149 | D5 PE8 D6 PE9 D7 PE10 |
|
151 | D5 PE8 D6 PE9 D7 PE10 | |
150 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
152 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S | |
151 | FSMC_NOE PD4 RD |
|
153 | FSMC_NOE PD4 RD | |
152 | */ |
|
154 | */ | |
153 |
|
155 | |||
154 | int bsp_FSMC_init() |
|
156 | int bsp_FSMC_init() | |
155 | { |
|
157 | { | |
156 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
158 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
157 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
159 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
158 |
|
160 | |||
159 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ |
|
161 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ | |
160 | ,PD4,PD5,PD7,PE4}; |
|
162 | ,PD4,PD5,PD7,PE4}; | |
161 | for(int i=0;i<12;i++) |
|
163 | for(int i=0;i<12;i++) | |
162 | { |
|
164 | { | |
163 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
165 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); | |
164 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
166 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
165 | gpiosetconfig(&LCD_DBx); |
|
167 | gpiosetconfig(&LCD_DBx); | |
166 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
168 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); | |
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
171 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; | |
170 |
FSMC_NORSRAMTimingInitTypeDef p |
|
172 | FSMC_NORSRAMTimingInitTypeDef p; | |
171 |
|
173 | |||
172 | /* Enable FSMC clock */ |
|
174 | /* Enable FSMC clock */ | |
173 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
175 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); | |
174 |
|
176 | |||
175 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
177 | /*-- FSMC Configuration ------------------------------------------------------*/ | |
176 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
178 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ | |
177 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
179 | /* FSMC_Bank1_NORSRAM4 configuration */ | |
178 | p.FSMC_AddressSetupTime = 3; |
|
180 | p.FSMC_AddressSetupTime = 3; | |
179 | p.FSMC_AddressHoldTime = 3; |
|
181 | p.FSMC_AddressHoldTime = 3; | |
180 | //ili9328 -> data setup time > 10ns |
|
182 | //ili9328 -> data setup time > 10ns | |
181 | p.FSMC_DataSetupTime = 1; |
|
183 | p.FSMC_DataSetupTime = 1; | |
182 | if(getCpuFreq()>100*1000*1000) |
|
184 | if(getCpuFreq()>100*1000*1000) | |
183 | p.FSMC_DataSetupTime = 2;// 11; |
|
185 | p.FSMC_DataSetupTime = 2;// 11; | |
184 | p.FSMC_BusTurnAroundDuration = 0; |
|
186 | p.FSMC_BusTurnAroundDuration = 0; | |
185 | p.FSMC_CLKDivision = 0; |
|
187 | p.FSMC_CLKDivision = 0; | |
186 | p.FSMC_DataLatency = 0; |
|
188 | p.FSMC_DataLatency = 0; | |
187 | //ili9328 -> data hold time > 15ns |
|
189 | //ili9328 -> data hold time > 15ns | |
188 | if(getCpuFreq()>66*1000*1000) |
|
190 | if(getCpuFreq()>66*1000*1000) | |
189 | p.FSMC_DataLatency = 0; |
|
191 | p.FSMC_DataLatency = 0; | |
190 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
192 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
191 |
|
193 | |||
192 |
|
194 | |||
193 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
195 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; | |
194 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
196 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
195 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
197 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; | |
196 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; |
|
198 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; | |
197 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
199 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
198 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
200 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
199 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
201 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
200 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
202 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
201 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
203 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
202 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
204 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
203 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
205 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
204 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
206 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
205 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
207 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
206 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
208 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
207 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
209 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
208 |
|
210 | |||
209 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
211 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
210 |
|
212 | |||
211 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
213 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); | |
212 | gpioset(LCD_RESET); |
|
214 | gpioset(LCD_RESET); | |
213 | gpioclr(LCD_RESET); |
|
215 | gpioclr(LCD_RESET); | |
214 | delay_100us(500); |
|
216 | delay_100us(500); | |
215 | gpioset(LCD_RESET); |
|
217 | gpioset(LCD_RESET); | |
216 | delay_100us(500); |
|
218 | delay_100us(500); | |
217 | lcd0.init(&lcd0); |
|
219 | lcd0.init(&lcd0); | |
218 | gpioset(LCD_BACKL); |
|
220 | gpioset(LCD_BACKL); | |
219 | return 1; |
|
221 | return 1; | |
220 | } |
|
222 | } | |
221 |
|
223 | |||
222 | void bsp_spi_init() |
|
224 | void bsp_spi_init() | |
223 | { |
|
225 | { | |
224 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; |
|
226 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; | |
225 | for(int i=0;i<3;i++) |
|
227 | for(int i=0;i<3;i++) | |
226 | { |
|
228 | { | |
227 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); |
|
229 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); | |
228 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
230 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
229 | gpiosetconfig(&SPI_DBx); |
|
231 | gpiosetconfig(&SPI_DBx); | |
230 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); |
|
232 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); | |
231 | } |
|
233 | } | |
232 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); |
|
234 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); | |
233 |
|
235 | |||
234 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; |
|
236 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; | |
235 | for(int i=0;i<3;i++) |
|
237 | for(int i=0;i<3;i++) | |
236 | { |
|
238 | { | |
237 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); |
|
239 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); | |
238 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
240 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
239 | gpiosetconfig(&SPI_DBx); |
|
241 | gpiosetconfig(&SPI_DBx); | |
240 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); |
|
242 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); | |
241 | } |
|
243 | } | |
242 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); |
|
244 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); | |
243 |
|
245 | |||
244 | } |
|
246 | } | |
245 |
|
247 | |||
246 |
|
248 | |||
247 | void bsp_iic_init() |
|
249 | void bsp_iic_init() | |
248 | { |
|
250 | { | |
249 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); |
|
251 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); | |
250 | } |
|
252 | } | |
251 |
|
253 | |||
252 |
|
254 | |||
253 | void bsp_Audio_init() |
|
255 | void bsp_Audio_init() | |
254 | { |
|
256 | { | |
255 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); |
|
257 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); | |
256 | if(audioCodec0.VERSION!=UNKNOWN) |
|
258 | if(audioCodec0.VERSION!=UNKNOWN) | |
257 | { |
|
259 | { | |
258 | printf("detected Audio codec "); |
|
260 | printf("detected Audio codec "); | |
259 | switch (audioCodec0.VERSION) { |
|
261 | switch (audioCodec0.VERSION) { | |
260 | case VS1001: |
|
262 | case VS1001: | |
261 | printf("VS1001\n"); |
|
263 | printf("VS1001\n"); | |
262 | break; |
|
264 | break; | |
263 | case VS1011: |
|
265 | case VS1011: | |
264 | printf("VS1011\n"); |
|
266 | printf("VS1011\n"); | |
265 | break; |
|
267 | break; | |
266 | case VS1002: |
|
268 | case VS1002: | |
267 | printf("VS1002\n"); |
|
269 | printf("VS1002\n"); | |
268 | break; |
|
270 | break; | |
269 | case VS1003: |
|
271 | case VS1003: | |
270 | printf("VS1003\n"); |
|
272 | printf("VS1003\n"); | |
271 | break; |
|
273 | break; | |
272 | case VS1053: |
|
274 | case VS1053: | |
273 | printf("VS1053\n"); |
|
275 | printf("VS1053\n"); | |
274 | break; |
|
276 | break; | |
275 | case VS1033: |
|
277 | case VS1033: | |
276 | printf("VS1033\n"); |
|
278 | printf("VS1033\n"); | |
277 | break; |
|
279 | break; | |
278 | case VS1103: |
|
280 | case VS1103: | |
279 | printf("VS1103\n"); |
|
281 | printf("VS1103\n"); | |
280 | break; |
|
282 | break; | |
281 | default: |
|
283 | default: | |
282 | printf("Unknown device\n"); |
|
284 | printf("Unknown device\n"); | |
283 | break; |
|
285 | break; | |
284 | } |
|
286 | } | |
285 | } |
|
287 | } | |
286 | } |
|
288 | } | |
287 |
|
289 | |||
288 | void bsp_SD_init() |
|
290 | void bsp_SD_init() | |
289 | { |
|
291 | { | |
290 | if(bspsdcardpresent()) |
|
292 | if(bspsdcardpresent()) | |
291 | { |
|
293 | { | |
292 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); |
|
294 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); | |
293 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); |
|
295 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
294 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) |
|
296 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) | |
295 | { |
|
297 | { | |
296 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) |
|
298 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) | |
297 | { |
|
299 | { | |
298 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) |
|
300 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) | |
299 | printf("Can't open fat32 partition 1\n"); |
|
301 | printf("Can't open fat32 partition 1\n"); | |
300 | } |
|
302 | } | |
301 | else |
|
303 | else | |
302 | { |
|
304 | { | |
303 | printf("Can't open or read MBR\n"); |
|
305 | printf("Can't open or read MBR\n"); | |
304 | } |
|
306 | } | |
305 | delay_100us(1000); |
|
307 | delay_100us(10000); | |
306 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
308 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) | |
307 | { |
|
309 | { | |
308 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
310 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) | |
309 | printf("Can't open fat32 partition 2\n"); |
|
311 | printf("Can't open fat32 partition 2\n"); | |
310 | } |
|
312 | } | |
311 | else |
|
313 | else | |
312 | { |
|
314 | { | |
313 | printf("Can't open or read MBR\n"); |
|
315 | printf("Can't open or read MBR\n"); | |
314 | } |
|
316 | } | |
315 | delay_100us(1000); |
|
317 | delay_100us(10000); | |
316 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
318 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) | |
317 | { |
|
319 | { | |
318 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
320 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) | |
319 | printf("Can't open fat32 partition 3\n"); |
|
321 | printf("Can't open fat32 partition 3\n"); | |
320 | } |
|
322 | } | |
321 | else |
|
323 | else | |
322 | { |
|
324 | { | |
323 | printf("Can't open or read MBR\n"); |
|
325 | printf("Can't open or read MBR\n"); | |
324 | } |
|
326 | } | |
325 | delay_100us(1000); |
|
327 | delay_100us(10000); | |
326 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
328 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) | |
327 | { |
|
329 | { | |
328 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
330 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) | |
329 | printf("Can't open fat32 partition 4\n"); |
|
331 | printf("Can't open fat32 partition 4\n"); | |
330 | } |
|
332 | } | |
331 | else |
|
333 | else | |
332 | { |
|
334 | { | |
333 | printf("Can't open or read MBR\n"); |
|
335 | printf("Can't open or read MBR\n"); | |
334 | } |
|
336 | } | |
335 | } |
|
337 | } | |
336 | else |
|
338 | else | |
337 | { |
|
339 | { | |
338 | printf("Can't initialize SDCARD\n"); |
|
340 | printf("Can't initialize SDCARD\n"); | |
339 | } |
|
341 | } | |
340 | } |
|
342 | } | |
341 | delay_100us(2000); |
|
343 | delay_100us(20000); | |
342 | } |
|
344 | } | |
343 |
|
345 | |||
344 | void vs1052setXCS(char val) |
|
346 | void vs1052setXCS(char val) | |
345 | { |
|
347 | { | |
346 | gpiosetval(VS1053xCS,(int)val); |
|
348 | gpiosetval(VS1053xCS,(int)val); | |
347 | } |
|
349 | } | |
348 |
|
350 | |||
349 | void vs1052setXDCS(char val) |
|
351 | void vs1052setXDCS(char val) | |
350 | { |
|
352 | { | |
351 | //gpiosetval(LED1,(int)val); |
|
353 | //gpiosetval(LED1,(int)val); | |
352 | gpiosetval(VS1053xDCS,(int)val); |
|
354 | gpiosetval(VS1053xDCS,(int)val); | |
353 | } |
|
355 | } | |
354 |
|
356 | |||
355 | void vs1052setRST(char val) |
|
357 | void vs1052setRST(char val) | |
356 | { |
|
358 | { | |
357 | if(val) |
|
359 | if(val) | |
358 | gpioset(VS1053xRESET); |
|
360 | gpioset(VS1053xRESET); | |
359 | else |
|
361 | else | |
360 | gpioclr(VS1053xRESET); |
|
362 | gpioclr(VS1053xRESET); | |
361 | } |
|
363 | } | |
362 |
|
364 | |||
363 | int vs10XXDREQ() |
|
365 | int vs10XXDREQ() | |
364 | { |
|
366 | { | |
365 | return gpiogetval(VS1053DREQ); |
|
367 | return gpiogetval(VS1053DREQ); | |
366 | } |
|
368 | } | |
367 |
|
369 | |||
368 |
|
370 | |||
369 | void bsppowersdcard(char onoff) //always ON |
|
371 | void bsppowersdcard(char onoff) //always ON | |
370 | { |
|
372 | { | |
371 |
|
373 | |||
372 | } |
|
374 | } | |
373 |
|
375 | |||
374 | char bspsdcardpresent() |
|
376 | char bspsdcardpresent() | |
375 | { |
|
377 | { | |
376 | return gpiogetval(SDCARD2CD); |
|
378 | return gpiogetval(SDCARD2CD); | |
377 | } |
|
379 | } | |
378 |
|
380 | |||
379 | char bspsdcardwriteprotected() |
|
381 | char bspsdcardwriteprotected() | |
380 | { |
|
382 | { | |
381 | return 0; |
|
383 | return 0; | |
382 | } |
|
384 | } | |
383 |
|
385 | |||
384 | void bspsdcardselect(char YESNO) |
|
386 | void bspsdcardselect(char YESNO) | |
385 | { |
|
387 | { | |
386 | // gpiosetval(LED1,(int)YESNO); |
|
388 | // gpiosetval(LED1,(int)YESNO); | |
387 | if(YESNO) |
|
389 | if(YESNO) | |
388 | gpioclr(SDCARD2CS); |
|
390 | gpioclr(SDCARD2CS); | |
389 | else |
|
391 | else | |
390 | gpioset(SDCARD2CS); |
|
392 | gpioset(SDCARD2CS); | |
391 | } |
|
393 | } | |
392 |
|
394 | |||
393 |
|
395 | |||
394 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
396 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
395 | { |
|
397 | { | |
396 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
398 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
397 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
399 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
398 | *lcd0_CMD=pt8[3]; |
|
400 | *lcd0_CMD=pt8[3]; | |
399 | *lcd0_CMD=pt8[2]; |
|
401 | *lcd0_CMD=pt8[2]; | |
400 | pt8 = (uint8_t*)(void*)&data; |
|
402 | pt8 = (uint8_t*)(void*)&data; | |
401 | *lcd0_DATA=pt8[3]; |
|
403 | *lcd0_DATA=pt8[3]; | |
402 | *lcd0_DATA=pt8[2]; |
|
404 | *lcd0_DATA=pt8[2]; | |
403 | #else |
|
405 | #else | |
404 |
|
||||
405 | *lcd0_CMD=pt8[1]; |
|
406 | *lcd0_CMD=pt8[1]; | |
406 | *lcd0_CMD=pt8[0]; |
|
407 | *lcd0_CMD=pt8[0]; | |
407 | pt8 = (uint8_t*)(void*)&data; |
|
408 | pt8 = (uint8_t*)(void*)&data; | |
408 | *lcd0_DATA=pt8[1]; |
|
409 | *lcd0_DATA=pt8[1]; | |
409 | *lcd0_DATA=pt8[0]; |
|
410 | *lcd0_DATA=pt8[0]; | |
410 | #endif |
|
411 | #endif | |
411 |
|
412 | |||
412 | } |
|
413 | } | |
413 |
|
414 | |||
414 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
415 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
415 | { |
|
416 | { | |
416 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
417 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
417 | uint32_t DATA=0; |
|
418 | uint32_t DATA=0; | |
418 |
|
419 | |||
419 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
420 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
420 | *lcd0_CMD=pt8[3]; |
|
421 | *lcd0_CMD=pt8[3]; | |
421 | *lcd0_CMD=pt8[2]; |
|
422 | *lcd0_CMD=pt8[2]; | |
422 | pt8 = (uint8_t*)(void*)&DATA; |
|
423 | pt8 = (uint8_t*)(void*)&DATA; | |
423 | pt8[3]=*lcd0_DATA; |
|
424 | pt8[3]=*lcd0_DATA; | |
424 | pt8[2]=*lcd0_DATA; |
|
425 | pt8[2]=*lcd0_DATA; | |
425 | #else |
|
426 | #else | |
426 |
|
||||
427 | *lcd0_CMD=pt8[1]; |
|
427 | *lcd0_CMD=pt8[1]; | |
428 | *lcd0_CMD=pt8[0]; |
|
428 | *lcd0_CMD=pt8[0]; | |
429 | pt8 = (uint8_t*)(void*)&DATA; |
|
429 | pt8 = (uint8_t*)(void*)&DATA; | |
430 | pt8[1]=*lcd0_DATA; |
|
430 | pt8[1]=*lcd0_DATA; | |
431 | pt8[0]=*lcd0_DATA; |
|
431 | pt8[0]=*lcd0_DATA; | |
432 | #endif |
|
432 | #endif | |
433 |
|
433 | |||
434 | return DATA; |
|
434 | return DATA; | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
437 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
438 | { |
|
438 | { | |
439 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
439 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
440 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
440 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
441 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
441 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
442 | *lcd0_CMD=pt8[3]; |
|
442 | *lcd0_CMD=pt8[3]; | |
443 | *lcd0_CMD=pt8[2]; |
|
443 | *lcd0_CMD=pt8[2]; | |
444 | pt8 = (uint8_t*)(void*)buffer; |
|
444 | pt8 = (uint8_t*)(void*)buffer; | |
445 | for(int i=0;i<(int)count;i++) |
|
445 | for(int i=0;i<(int)count;i++) | |
446 | { |
|
446 | { | |
447 | *lcd0_DATA=pt8[(2*i) +1]; |
|
447 | *lcd0_DATA=pt8[(2*i) +1]; | |
448 | *lcd0_DATA=pt8[2*i]; |
|
448 | *lcd0_DATA=pt8[2*i]; | |
449 | } |
|
449 | } | |
450 | #else |
|
450 | #else | |
451 |
|
||||
452 | *lcd0_CMD=pt8[1]; |
|
451 | *lcd0_CMD=pt8[1]; | |
453 | *lcd0_CMD=pt8[0]; |
|
452 | *lcd0_CMD=pt8[0]; | |
454 | pt8 = (uint8_t*)(void*)buffer; |
|
453 | pt8 = (uint8_t*)(void*)buffer; | |
455 | for(int i=0;i<(int)count;i++) |
|
454 | for(int i=0;i<(int)count;i++) | |
456 | { |
|
455 | { | |
457 |
|
456 | |||
458 | *lcd0_DATA=pt8[(2*i) +1]; |
|
457 | *lcd0_DATA=pt8[(2*i) +1]; | |
459 | *lcd0_DATA=pt8[2*i]; |
|
458 | *lcd0_DATA=pt8[2*i]; | |
460 | } |
|
459 | } | |
461 | #endif |
|
460 | #endif | |
462 | } |
|
461 | } | |
463 |
|
462 | |||
464 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
463 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
465 | { |
|
464 | { | |
466 | //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
465 | //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
467 |
volatile uint8_t* pt8 |
|
466 | volatile uint8_t* pt8;// = (uint8_t*)(void*)® | |
468 | /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
467 | /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
469 | *lcd0_CMD=pt8[3]; |
|
468 | *lcd0_CMD=pt8[3]; | |
470 | *lcd0_CMD=pt8[2]; |
|
469 | *lcd0_CMD=pt8[2]; | |
471 | pt8 = (uint8_t*)(void*)buffer; |
|
470 | pt8 = (uint8_t*)(void*)buffer; | |
472 | for(int i=0;i<(int)count;i++) |
|
471 | for(int i=0;i<(int)count;i++) | |
473 | { |
|
472 | { | |
474 | pt8[(2*i) +1]=*lcd0_DATA; |
|
473 | pt8[(2*i) +1]=*lcd0_DATA; | |
475 | pt8[2*i]=*lcd0_DATA; |
|
474 | pt8[2*i]=*lcd0_DATA; | |
476 | } |
|
475 | } | |
477 | #else |
|
476 | #else | |
478 | *lcd0_CMD=(uint8_t)0; |
|
477 | *lcd0_CMD=(uint8_t)0; | |
479 | *lcd0_CMD=(uint8_t)0; |
|
478 | *lcd0_CMD=(uint8_t)0; | |
480 | *lcd0_CMD=(uint8_t)0; |
|
479 | *lcd0_CMD=(uint8_t)0; | |
481 | *lcd0_CMD=(uint8_t)0; |
|
480 | *lcd0_CMD=(uint8_t)0; | |
482 | *lcd0_CMD=pt8[1]; |
|
481 | *lcd0_CMD=pt8[1]; | |
483 | *lcd0_CMD=pt8[0]; |
|
482 | *lcd0_CMD=pt8[0]; | |
484 | pt8 = (uint8_t*)buffer;*/ |
|
483 | pt8 = (uint8_t*)buffer;*/ | |
485 | /* |
|
484 | /* | |
486 | * x dummy reads Cf ili9328 datasheet p79! |
|
485 | * x dummy reads Cf ili9328 datasheet p79! | |
487 | */ |
|
486 | */ | |
488 | /* pt8[0]=*lcd0_DATA; |
|
487 | /* pt8[0]=*lcd0_DATA; | |
489 | pt8[1]=*lcd0_DATA; |
|
488 | pt8[1]=*lcd0_DATA; | |
490 |
|
489 | |||
491 | for(int i=0;i<(int)count;i++) |
|
490 | for(int i=0;i<(int)count;i++) | |
492 | { |
|
491 | { | |
493 | pt8[(2*i) +1]=*lcd0_DATA; |
|
492 | pt8[(2*i) +1]=*lcd0_DATA; | |
494 | pt8[2*i]=*lcd0_DATA; |
|
493 | pt8[2*i]=*lcd0_DATA; | |
495 | pt8[(2*i) +1]=*lcd0_DATA; |
|
494 | pt8[(2*i) +1]=*lcd0_DATA; | |
496 | pt8[2*i]=*lcd0_DATA; |
|
495 | pt8[2*i]=*lcd0_DATA; | |
497 | } |
|
496 | } | |
498 | #endif*/ |
|
497 | #endif*/ | |
499 |
|
498 | |||
500 |
*lcd0_CMD=( |
|
499 | *lcd0_CMD=(int8_t)0; | |
501 |
*lcd0_CMD=( |
|
500 | // *lcd0_CMD=(int8_t)0x22; | |
|
501 | *lcd0_CMD=(int8_t)0x00; | |||
502 | pt8 = (uint8_t*)buffer; |
|
502 | pt8 = (uint8_t*)buffer; | |
503 | pt8[1]=*lcd0_DATA; |
|
503 | pt8[1]=*lcd0_DATA; | |
504 | pt8[0]=*lcd0_DATA; |
|
504 | pt8[0]=*lcd0_DATA; | |
505 | for(int i=0;i<(int)count;i++) |
|
505 | for(int i=0;i<(int)count;i++) | |
506 | { |
|
506 | { | |
507 | //pt8[(2*i) +1]=0; |
|
|||
508 | //pt8[2*i]=0; |
|
|||
509 | pt8[(2*i)+1]= *lcd0_DATA; |
|
507 | pt8[(2*i)+1]= *lcd0_DATA; | |
510 | pt8[2*i]= *lcd0_DATA; |
|
508 | pt8[2*i]= *lcd0_DATA; | |
511 | } |
|
509 | } | |
512 | } |
|
510 | } | |
513 |
|
511 | |||
514 | void bsp_GTerm_init() |
|
512 | void bsp_GTerm_init() | |
515 | { |
|
513 | { | |
516 | if(__opnfiles__[1]==NULL) |
|
514 | if(__opnfiles__[1]==NULL) | |
517 | { |
|
515 | { | |
518 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
516 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
519 |
terminal_init(&terminal0 ,&lcd0,&ComicSansMS_ |
|
517 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | |
520 | __opnfiles__[1] = fd1; |
|
518 | __opnfiles__[1] = fd1; | |
521 | } |
|
519 | } | |
522 | else |
|
520 | else | |
523 | { |
|
521 | { | |
524 |
|
522 | |||
525 | } |
|
523 | } | |
526 | } |
|
524 | } | |
527 |
|
525 | |||
528 |
|
526 | |||
529 |
|
527 | |||
530 |
|
528 | |||
531 |
|
529 | |||
532 |
|
530 | |||
533 |
|
531 | |||
534 |
|
532 | |||
535 |
|
533 | |||
536 |
|
534 | |||
537 |
|
535 | |||
538 |
|
536 | |||
539 |
|
537 | |||
540 |
|
538 | |||
541 |
|
539 | |||
542 |
|
540 | |||
543 |
|
541 |
@@ -1,133 +1,134 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef BSP_H |
|
22 | #ifndef BSP_H | |
23 | #define BSP_H |
|
23 | #define BSP_H | |
24 | #include <stm32f4xx.h> |
|
24 | #include <stm32f4xx.h> | |
25 | #include <stm32f4xx_gpio.h> |
|
25 | #include <stm32f4xx_gpio.h> | |
26 | #include <stm32f4xx_rcc.h> |
|
26 | #include <stm32f4xx_rcc.h> | |
27 | #include <gpio.h> |
|
27 | #include <gpio.h> | |
28 | #include <spi.h> |
|
28 | #include <spi.h> | |
29 | #include <ili9328.h> |
|
29 | #include <ili9328.h> | |
30 | #include <genericLCD_Controler.h> |
|
30 | #include <genericLCD_Controler.h> | |
31 | #include <sdcard-spi.h> |
|
31 | #include <sdcard-spi.h> | |
32 | #include <sdcard.h> |
|
32 | #include <sdcard.h> | |
33 | #include <mbr.h> |
|
33 | #include <mbr.h> | |
34 | #include <VS10XX.h> |
|
34 | #include <VS10XX.h> | |
35 | #include <fat32.h> |
|
35 | #include <fat32.h> | |
36 |
|
36 | |||
37 | #define __MAX_OPENED_FILES__ 4 |
|
37 | #define __MAX_OPENED_FILES__ 4 | |
38 | #define __FS_ROOT_SIZE__ 4 |
|
38 | #define __FS_ROOT_SIZE__ 4 | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | #define LED1 PC15 |
|
41 | #define LED1 PC15 | |
42 | #define LED2 PC14 |
|
42 | #define LED2 PC14 | |
43 |
|
43 | |||
44 | #define BP3 PA0 |
|
44 | #define BP3 PA0 | |
45 |
|
45 | |||
46 | #define LCD_RESET PD10 |
|
46 | #define LCD_RESET PD10 | |
47 | #define LCD_BACKL PE11 |
|
47 | #define LCD_BACKL PE11 | |
|
48 | #define LCD_RS PE4 | |||
48 |
|
49 | |||
49 | #define VS1053SPI spi1 |
|
50 | #define VS1053SPI spi1 | |
50 | #define VS1053xCS PA3 |
|
51 | #define VS1053xCS PA3 | |
51 | #define VS1053xRESET PA2 |
|
52 | #define VS1053xRESET PA2 | |
52 | #define VS1053xDCS PA4 |
|
53 | #define VS1053xDCS PA4 | |
53 | #define VS1053DREQ PA1 |
|
54 | #define VS1053DREQ PA1 | |
54 | #define VS1053MISO PA6 |
|
55 | #define VS1053MISO PA6 | |
55 | #define VS1053MOSI PA7 |
|
56 | #define VS1053MOSI PA7 | |
56 | #define VS1053SCK PA5 |
|
57 | #define VS1053SCK PA5 | |
57 |
|
58 | |||
58 |
|
59 | |||
59 |
|
60 | |||
60 | #define SDCARD2SPI spi3 |
|
61 | #define SDCARD2SPI spi3 | |
61 | #define SDCARD2CS PB8 |
|
62 | #define SDCARD2CS PB8 | |
62 | #define SDCARD2CD PB9 |
|
63 | #define SDCARD2CD PB9 | |
63 | #define SDCARD2MISO PB4 |
|
64 | #define SDCARD2MISO PB4 | |
64 | #define SDCARD2MOSI PB5 |
|
65 | #define SDCARD2MOSI PB5 | |
65 | #define SDCARD2SCK PB3 |
|
66 | #define SDCARD2SCK PB3 | |
66 |
|
67 | |||
67 | extern float VREF0; |
|
68 | extern float VREF0; | |
68 |
|
69 | |||
69 | extern uint32_t currentCpuFreq; |
|
70 | extern uint32_t currentCpuFreq; | |
70 | extern LCD_t lcd0; |
|
71 | extern LCD_t lcd0; | |
71 |
|
72 | |||
72 | extern volatile vs10XXDev audioCodec0; |
|
73 | extern volatile vs10XXDev audioCodec0; | |
73 |
|
74 | |||
74 | extern sdcardDev sdcard2; |
|
75 | extern sdcardDev sdcard2; | |
75 | extern blkdevice sdcard2blkdev; |
|
76 | extern blkdevice sdcard2blkdev; | |
76 | extern dikpartition sdcard2Part1; |
|
77 | extern dikpartition sdcard2Part1; | |
77 | extern FAT32fs sdcard2FAT32part1; |
|
78 | extern FAT32fs sdcard2FAT32part1; | |
78 | extern dikpartition sdcard2Part2; |
|
79 | extern dikpartition sdcard2Part2; | |
79 | extern FAT32fs sdcard2FAT32part2; |
|
80 | extern FAT32fs sdcard2FAT32part2; | |
80 | extern dikpartition sdcard2Part3; |
|
81 | extern dikpartition sdcard2Part3; | |
81 | extern FAT32fs sdcard2FAT32part3; |
|
82 | extern FAT32fs sdcard2FAT32part3; | |
82 | extern dikpartition sdcard2Part4; |
|
83 | extern dikpartition sdcard2Part4; | |
83 | extern FAT32fs sdcard2FAT32part4; |
|
84 | extern FAT32fs sdcard2FAT32part4; | |
84 |
|
85 | |||
85 | extern int bsp_init(); |
|
86 | extern int bsp_init(); | |
86 |
|
87 | |||
87 | extern void bsp_GPIO_init(); |
|
88 | extern void bsp_GPIO_init(); | |
88 | extern void bsp_uart_init(); |
|
89 | extern void bsp_uart_init(); | |
89 | extern void bsp_iic_init(); |
|
90 | extern void bsp_iic_init(); | |
90 | extern void bsp_spi_init(); |
|
91 | extern void bsp_spi_init(); | |
91 | extern void bsp_SD_init(); |
|
92 | extern void bsp_SD_init(); | |
92 | extern void bsp_Audio_init(); |
|
93 | extern void bsp_Audio_init(); | |
93 | extern void bsp_GTerm_init(); |
|
94 | extern void bsp_GTerm_init(); | |
94 | extern int bsp_FSMC_init(); |
|
95 | extern int bsp_FSMC_init(); | |
95 |
|
96 | |||
96 | /* VS1053 */ |
|
97 | /* VS1053 */ | |
97 | extern void vs1052setXCS(char val); |
|
98 | extern void vs1052setXCS(char val); | |
98 | extern void vs1052setXDCS(char val); |
|
99 | extern void vs1052setXDCS(char val); | |
99 | extern void vs1052setRST(char val); |
|
100 | extern void vs1052setRST(char val); | |
100 | extern int vs10XXDREQ(); |
|
101 | extern int vs10XXDREQ(); | |
101 |
|
102 | |||
102 | /* SD CARD */ |
|
103 | /* SD CARD */ | |
103 | void bsppowersdcard(char onoff); |
|
104 | void bsppowersdcard(char onoff); | |
104 | char bspsdcardpresent(); |
|
105 | char bspsdcardpresent(); | |
105 | void bspsdcardselect(char YESNO); |
|
106 | void bspsdcardselect(char YESNO); | |
106 | char bspsdcardwriteprotected(); |
|
107 | char bspsdcardwriteprotected(); | |
107 |
|
108 | |||
108 |
|
109 | |||
109 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); |
|
110 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); | |
110 | uint32_t bsp_lcd0_read_reg(uint32_t reg); |
|
111 | uint32_t bsp_lcd0_read_reg(uint32_t reg); | |
111 | void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); |
|
112 | void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); | |
112 | void bsp_lcd0_readGRAM(void *buffer, uint32_t count); |
|
113 | void bsp_lcd0_readGRAM(void *buffer, uint32_t count); | |
113 |
|
114 | |||
114 | #endif |
|
115 | #endif | |
115 |
|
116 | |||
116 |
|
117 | |||
117 |
|
118 | |||
118 |
|
119 | |||
119 |
|
120 | |||
120 |
|
121 | |||
121 |
|
122 | |||
122 |
|
123 | |||
123 |
|
124 | |||
124 |
|
125 | |||
125 |
|
126 | |||
126 |
|
127 | |||
127 |
|
128 | |||
128 |
|
129 | |||
129 |
|
130 | |||
130 |
|
131 | |||
131 |
|
132 | |||
132 |
|
133 | |||
133 |
|
134 |
@@ -1,284 +1,332 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include "bsp.h" |
|
22 | #include "bsp.h" | |
23 | #include <streamdevices.h> |
|
23 | #include <streamdevices.h> | |
24 | #include <malloc.h> |
|
24 | #include <malloc.h> | |
25 | #include <stdio.h> |
|
25 | #include <stdio.h> | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | uint32_t OSC0 =8000000; |
|
28 | uint32_t OSC0 =8000000; | |
29 | uint32_t INTOSC =16000000; |
|
29 | uint32_t INTOSC =16000000; | |
30 | uint32_t RTCOSC =32768; |
|
30 | uint32_t RTCOSC =32768; | |
31 | uint32_t currentCpuFreq=0; |
|
31 | uint32_t currentCpuFreq=0; | |
32 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
32 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | LCD_IF_t lcdIF0={ |
|
35 | LCD_IF_t lcdIF0={ | |
36 | .init = &SDLCD_init, |
|
36 | .init = &SDLCD_init, | |
37 | .writereg = &SDLCD_writereg, |
|
37 | .writereg = &SDLCD_writereg, | |
38 | .readreg = &SDLCD_readreg, |
|
38 | .readreg = &SDLCD_readreg, | |
39 | .writeGRAM = &SDLCD_writeGRAM_16bpp, |
|
39 | .writeGRAM = &SDLCD_writeGRAM_16bpp, | |
40 | .readGRAM = &SDLCD_readGRAM_16bpp |
|
40 | .readGRAM = &SDLCD_readGRAM_16bpp | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | LCD_t lcd0={ |
|
43 | LCD_t lcd0={ | |
44 | .interface = &lcdIF0, |
|
44 | .interface = &lcdIF0, | |
45 | .init = &ili9328init, |
|
45 | .init = &ili9328init, | |
46 | .paint = &ili9328paint, |
|
46 | .paint = &ili9328paint, | |
47 | .paintText = &ili9328paintText, |
|
47 | .paintText = &ili9328paintText, | |
48 | .paintFilRect = &ili9328paintFilRect, |
|
48 | .paintFilRect = &ili9328paintFilRect, | |
49 | .getPix = &ili9328getPix, |
|
49 | .getPix = &ili9328getPix, | |
50 | .refreshenable = &ili9328refreshenable, |
|
50 | .refreshenable = &ili9328refreshenable, | |
51 | .width= 240, |
|
51 | .width= 240, | |
52 | .height = 320 |
|
52 | .height = 320 | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | terminal_t terminal0; |
|
55 | terminal_t terminal0; | |
56 |
|
56 | |||
57 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; |
|
57 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; | |
58 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); |
|
58 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); | |
59 |
|
59 | |||
60 | float VREF0 =(float)3.3; |
|
60 | float VREF0 =(float)3.3; | |
61 | volatile vs10XXDev audioCodec0; |
|
61 | volatile vs10XXDev audioCodec0; | |
62 |
|
62 | |||
63 | sdcardDev sdcard2; |
|
63 | sdcardDev sdcard2; | |
64 | blkdevice sdcard2blkdev; |
|
64 | blkdevice sdcard2blkdev; | |
65 | dikpartition sdcard2Part1; |
|
65 | dikpartition sdcard2Part1; | |
66 | FAT32fs sdcard2FAT32part1; |
|
66 | FAT32fs sdcard2FAT32part1; | |
67 | dikpartition sdcard2Part2; |
|
67 | dikpartition sdcard2Part2; | |
68 | FAT32fs sdcard2FAT32part2; |
|
68 | FAT32fs sdcard2FAT32part2; | |
69 | dikpartition sdcard2Part3; |
|
69 | dikpartition sdcard2Part3; | |
70 | FAT32fs sdcard2FAT32part3; |
|
70 | FAT32fs sdcard2FAT32part3; | |
71 | dikpartition sdcard2Part4; |
|
71 | dikpartition sdcard2Part4; | |
72 | FAT32fs sdcard2FAT32part4; |
|
72 | FAT32fs sdcard2FAT32part4; | |
73 |
|
73 | |||
74 | int bsp_init() |
|
74 | int bsp_init() | |
75 | { |
|
75 | { | |
76 | int i=0; |
|
76 | int i=0; | |
77 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
77 | for(i=0;i<__MAX_OPENED_FILES__;i++) | |
78 | { |
|
78 | { | |
79 | __opnfiles__[i] = NULL; |
|
79 | __opnfiles__[i] = NULL; | |
80 | } |
|
80 | } | |
81 | bsp_GPIO_init(); |
|
81 | bsp_GPIO_init(); | |
82 | bsp_uart_init(); |
|
82 | bsp_uart_init(); | |
83 | bsp_iic_init(); |
|
83 | bsp_iic_init(); | |
84 | bsp_FSMC_init(); |
|
84 | bsp_FSMC_init(); | |
85 | bsp_GTerm_init(); |
|
85 | bsp_GTerm_init(); | |
86 | bsp_spi_init(); |
|
86 | bsp_spi_init(); | |
87 | bsp_SD_init(); |
|
87 | bsp_SD_init(); | |
88 | bsp_Audio_init(); |
|
88 | bsp_Audio_init(); | |
89 | printf("\r=====================\n\r"); |
|
89 | printf("\r=====================\n\r"); | |
90 | printf( "=====================\n\r"); |
|
90 | printf( "=====================\n\r"); | |
91 | printf(BSP); |
|
91 | printf(BSP); | |
92 | printf(" initialised\n\r"); |
|
92 | printf(" initialised\n\r"); | |
93 | printf( "=====================\n\r"); |
|
93 | printf( "=====================\n\r"); | |
94 | return 1; |
|
94 | return 1; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void bsp_GPIO_init() |
|
97 | void bsp_GPIO_init() | |
98 | { |
|
98 | { | |
99 |
|
99 | |||
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void bsp_uart_init() |
|
102 | void bsp_uart_init() | |
103 | { |
|
103 | { | |
104 |
|
104 | |||
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /* |
|
107 | /* | |
108 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
108 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 | |
109 | D5 PE8 D6 PE9 D7 PE10 |
|
109 | D5 PE8 D6 PE9 D7 PE10 | |
110 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
110 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S | |
111 | FSMC_NOE PD4 RD |
|
111 | FSMC_NOE PD4 RD | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | int bsp_FSMC_init() |
|
114 | int bsp_FSMC_init() | |
115 | { |
|
115 | { | |
116 |
|
116 | |||
117 | return 1; |
|
117 | return 1; | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void bsp_spi_init() |
|
120 | void bsp_spi_init() | |
121 | { |
|
121 | { | |
122 |
|
122 | |||
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 |
|
125 | |||
126 | void bsp_iic_init() |
|
126 | void bsp_iic_init() | |
127 | { |
|
127 | { | |
128 |
|
128 | |||
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | void bsp_Audio_init() |
|
132 | void bsp_Audio_init() | |
133 | { |
|
133 | { | |
134 |
|
134 | |||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void bsp_SD_init() |
|
137 | void bsp_SD_init() | |
138 | { |
|
138 | { | |
139 |
|
139 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | ||
|
140 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) | |||
|
141 | { | |||
|
142 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) | |||
|
143 | { | |||
|
144 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) | |||
|
145 | printf("Can't open fat32 partition 1\n"); | |||
|
146 | } | |||
|
147 | else | |||
|
148 | { | |||
|
149 | printf("Can't open or read MBR\n"); | |||
|
150 | } | |||
|
151 | delay_100us(1000); | |||
|
152 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) | |||
|
153 | { | |||
|
154 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) | |||
|
155 | printf("Can't open fat32 partition 2\n"); | |||
|
156 | } | |||
|
157 | else | |||
|
158 | { | |||
|
159 | printf("Can't open or read MBR\n"); | |||
|
160 | } | |||
|
161 | delay_100us(1000); | |||
|
162 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) | |||
|
163 | { | |||
|
164 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) | |||
|
165 | printf("Can't open fat32 partition 3\n"); | |||
|
166 | } | |||
|
167 | else | |||
|
168 | { | |||
|
169 | printf("Can't open or read MBR\n"); | |||
|
170 | } | |||
|
171 | delay_100us(1000); | |||
|
172 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) | |||
|
173 | { | |||
|
174 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) | |||
|
175 | printf("Can't open fat32 partition 4\n"); | |||
|
176 | } | |||
|
177 | else | |||
|
178 | { | |||
|
179 | printf("Can't open or read MBR\n"); | |||
|
180 | } | |||
|
181 | } | |||
|
182 | else | |||
|
183 | { | |||
|
184 | printf("Can't initialize SDCARD\n"); | |||
|
185 | } | |||
|
186 | ||||
|
187 | delay_100us(2000); | |||
140 | } |
|
188 | } | |
141 |
|
189 | |||
142 | void vs1052setXCS(char val) |
|
190 | void vs1052setXCS(char val) | |
143 | { |
|
191 | { | |
144 | } |
|
192 | } | |
145 |
|
193 | |||
146 | void vs1052setXDCS(char val) |
|
194 | void vs1052setXDCS(char val) | |
147 | { |
|
195 | { | |
148 | } |
|
196 | } | |
149 |
|
197 | |||
150 | void vs1052setRST(char val) |
|
198 | void vs1052setRST(char val) | |
151 | { |
|
199 | { | |
152 | } |
|
200 | } | |
153 |
|
201 | |||
154 | int vs10XXDREQ() |
|
202 | int vs10XXDREQ() | |
155 | { |
|
203 | { | |
156 | return 1; |
|
204 | return 1; | |
157 | } |
|
205 | } | |
158 |
|
206 | |||
159 |
|
207 | |||
160 | void bsppowersdcard(char onoff) //always ON |
|
208 | void bsppowersdcard(char onoff) //always ON | |
161 | { |
|
209 | { | |
162 |
|
210 | |||
163 | } |
|
211 | } | |
164 |
|
212 | |||
165 | char bspsdcardpresent() |
|
213 | char bspsdcardpresent() | |
166 | { |
|
214 | { | |
167 | return 1; |
|
215 | return 1; | |
168 | } |
|
216 | } | |
169 |
|
217 | |||
170 | char bspsdcardwriteprotected() |
|
218 | char bspsdcardwriteprotected() | |
171 | { |
|
219 | { | |
172 | return 0; |
|
220 | return 0; | |
173 | } |
|
221 | } | |
174 |
|
222 | |||
175 | void bspsdcardselect(char YESNO) |
|
223 | void bspsdcardselect(char YESNO) | |
176 | { |
|
224 | { | |
177 |
|
225 | |||
178 | } |
|
226 | } | |
179 |
|
227 | |||
180 |
|
228 | |||
181 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
229 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
182 | { |
|
230 | { | |
183 |
|
231 | |||
184 | } |
|
232 | } | |
185 |
|
233 | |||
186 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
234 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
187 | { |
|
235 | { | |
188 | return 0; |
|
236 | return 0; | |
189 | } |
|
237 | } | |
190 |
|
238 | |||
191 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
239 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
192 | { |
|
240 | { | |
193 |
|
241 | |||
194 | } |
|
242 | } | |
195 |
|
243 | |||
196 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
244 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
197 | { |
|
245 | { | |
198 |
|
246 | |||
199 | } |
|
247 | } | |
200 |
|
248 | |||
201 | void bsp_GTerm_init() |
|
249 | void bsp_GTerm_init() | |
202 | { |
|
250 | { | |
203 | SDLCD_mkscreen(240,320,16,LCDILI9328); |
|
251 | SDLCD_mkscreen(240,320,16,LCDILI9328); | |
204 |
|
252 | |||
205 | if(__opnfiles__[1]==NULL) |
|
253 | if(__opnfiles__[1]==NULL) | |
206 | { |
|
254 | { | |
207 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
255 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
208 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); |
|
256 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); | |
209 | lcd0.paintFilRect(&lcd0,0,0,240,320,0,0,0x0f0f); |
|
257 | lcd0.paintFilRect(&lcd0,0,0,240,320,0,0,0x0f0f); | |
210 | __opnfiles__[1] = fd1; |
|
258 | __opnfiles__[1] = fd1; | |
211 | } |
|
259 | } | |
212 | else |
|
260 | else | |
213 | { |
|
261 | { | |
214 |
|
262 | |||
215 | } |
|
263 | } | |
216 | } |
|
264 | } | |
217 |
|
265 | |||
218 |
|
266 | |||
219 |
|
267 | |||
220 |
|
268 | |||
221 |
|
269 | |||
222 |
|
270 | |||
223 |
|
271 | |||
224 | void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
272 | void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) | |
225 | { |
|
273 | { | |
226 | int bpp = surface->format->BytesPerPixel; |
|
274 | int bpp = surface->format->BytesPerPixel; | |
227 | /* Here p is the address to the pixel we want to set */ |
|
275 | /* Here p is the address to the pixel we want to set */ | |
228 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
276 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
229 | switch(bpp) { |
|
277 | switch(bpp) { | |
230 | case 1: |
|
278 | case 1: | |
231 | *p = pixel; |
|
279 | *p = pixel; | |
232 | break; |
|
280 | break; | |
233 | case 2: |
|
281 | case 2: | |
234 | *(Uint16 *)p = pixel; |
|
282 | *(Uint16 *)p = pixel; | |
235 | break; |
|
283 | break; | |
236 | case 3: |
|
284 | case 3: | |
237 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
285 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { | |
238 | p[0] = (pixel >> 16) & 0xff; |
|
286 | p[0] = (pixel >> 16) & 0xff; | |
239 | p[1] = (pixel >> 8) & 0xff; |
|
287 | p[1] = (pixel >> 8) & 0xff; | |
240 | p[2] = pixel & 0xff; |
|
288 | p[2] = pixel & 0xff; | |
241 | } else { |
|
289 | } else { | |
242 | p[0] = pixel & 0xff; |
|
290 | p[0] = pixel & 0xff; | |
243 | p[1] = (pixel >> 8) & 0xff; |
|
291 | p[1] = (pixel >> 8) & 0xff; | |
244 | p[2] = (pixel >> 16) & 0xff; |
|
292 | p[2] = (pixel >> 16) & 0xff; | |
245 | } |
|
293 | } | |
246 | break; |
|
294 | break; | |
247 | case 4: |
|
295 | case 4: | |
248 | *(Uint32 *)p = pixel; |
|
296 | *(Uint32 *)p = pixel; | |
249 | break; |
|
297 | break; | |
250 | } |
|
298 | } | |
251 | } |
|
299 | } | |
252 |
|
300 | |||
253 | Uint32 getpixel(SDL_Surface *surface, int x, int y) |
|
301 | Uint32 getpixel(SDL_Surface *surface, int x, int y) | |
254 | { |
|
302 | { | |
255 | int bpp = surface->format->BytesPerPixel; |
|
303 | int bpp = surface->format->BytesPerPixel; | |
256 | /* Here p is the address to the pixel we want to retrieve */ |
|
304 | /* Here p is the address to the pixel we want to retrieve */ | |
257 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
305 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
258 | switch(bpp) { |
|
306 | switch(bpp) { | |
259 | case 1: |
|
307 | case 1: | |
260 | return *p; |
|
308 | return *p; | |
261 | case 2: |
|
309 | case 2: | |
262 | return *(Uint16 *)p; |
|
310 | return *(Uint16 *)p; | |
263 | case 3: |
|
311 | case 3: | |
264 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
312 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
265 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
313 | return p[0] << 16 | p[1] << 8 | p[2]; | |
266 | else |
|
314 | else | |
267 | return p[0] | p[1] << 8 | p[2] << 16; |
|
315 | return p[0] | p[1] << 8 | p[2] << 16; | |
268 | case 4: |
|
316 | case 4: | |
269 | return *(Uint32 *)p; |
|
317 | return *(Uint32 *)p; | |
270 | default: |
|
318 | default: | |
271 | return 0; |
|
319 | return 0; | |
272 | } |
|
320 | } | |
273 | /* shouldnβt happen, but avoids warnings */ |
|
321 | /* shouldnβt happen, but avoids warnings */ | |
274 | } |
|
322 | } | |
275 |
|
323 | |||
276 |
|
324 | |||
277 |
|
325 | |||
278 |
|
326 | |||
279 |
|
327 | |||
280 |
|
328 | |||
281 |
|
329 | |||
282 |
|
330 | |||
283 |
|
331 | |||
284 |
|
332 |
@@ -1,229 +1,229 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <stm32f4xx.h> |
|
5 | #include <stm32f4xx.h> | |
6 | #include <bsp.h> |
|
6 | #include <bsp.h> | |
7 | #include <core.h> |
|
7 | #include <core.h> | |
8 | #include <VS10XX.h> |
|
8 | #include <VS10XX.h> | |
9 | #include <bsp.h> |
|
9 | #include <bsp.h> | |
10 | #include <spi.h> |
|
10 | #include <spi.h> | |
11 | #include <sdcard.h> |
|
11 | #include <sdcard.h> | |
12 | #include <sdcard-spi.h> |
|
12 | #include <sdcard-spi.h> | |
13 | #include <fat32.h> |
|
13 | #include <fat32.h> | |
14 | #include <ucdirent.h> |
|
14 | #include <ucdirent.h> | |
15 | #include <string.h> |
|
15 | #include <string.h> | |
16 | #include <terminal.h> |
|
16 | #include <terminal.h> | |
17 | #include <ili9328.h> |
|
17 | #include <ili9328.h> | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | extern streamdevice* __opnfiles__[]; |
|
20 | extern streamdevice* __opnfiles__[]; | |
21 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
21 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); | |
22 | extern void test_all_colors(LCD_t* LCD); |
|
22 | extern void test_all_colors(LCD_t* LCD); | |
23 | extern void test_small_lines(LCD_t* LCD); |
|
23 | extern void test_small_lines(LCD_t* LCD); | |
24 | extern void test_lines(LCD_t* LCD); |
|
24 | extern void test_lines(LCD_t* LCD); | |
25 | extern void test_address(LCD_t* LCD); |
|
25 | extern void test_address(LCD_t* LCD); | |
26 | void test_uniform_rw(LCD_t* LCD); |
|
26 | void test_uniform_rw(LCD_t* LCD); | |
27 | char buffer[512]; |
|
27 | char buffer[512]; | |
28 |
|
28 | |||
29 | void randBoxesDemo() |
|
29 | void randBoxesDemo() | |
30 | { |
|
30 | { | |
31 | int16_t x,y,w,h,t,r; |
|
31 | int16_t x,y,w,h,t,r; | |
32 | x=rand()%240; |
|
32 | x=rand()%240; | |
33 | y=rand()%320; |
|
33 | y=rand()%320; | |
34 | w=rand()%(240-x); |
|
34 | w=rand()%(240-x); | |
35 | if(x>y) |
|
35 | if(x>y) | |
36 | r=(rand()%(y))%(320-y); |
|
36 | r=(rand()%(y))%(320-y); | |
37 | else |
|
37 | else | |
38 | r=(rand()%(x))%(240-x); |
|
38 | r=(rand()%(x))%(240-x); | |
39 | h=rand()%(320-y); |
|
39 | h=rand()%(320-y); | |
40 | t=rand()%(10); |
|
40 | t=rand()%(10); | |
41 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
41 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); | |
42 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
42 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); | |
43 | //delay_100us(10); |
|
43 | //delay_100us(10); | |
44 | //for(volatile int i=0;i<(1024*2);i++); |
|
44 | //for(volatile int i=0;i<(1024*2);i++); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void randTextDemo() |
|
47 | void randTextDemo() | |
48 | { |
|
48 | { | |
49 | int16_t x,y,w,h,t,r; |
|
49 | int16_t x,y,w,h,t,r; | |
50 | char buf[2]; |
|
50 | char buf[2]; | |
51 | buf[1]='\0'; |
|
51 | buf[1]='\0'; | |
52 | x=rand()%240; |
|
52 | x=rand()%240; | |
53 | y=rand()%320; |
|
53 | y=rand()%320; | |
54 | if(x>y) |
|
54 | if(x>y) | |
55 | r=(rand()%(y))%(320-y); |
|
55 | r=(rand()%(y))%(320-y); | |
56 | else |
|
56 | else | |
57 | r=(rand()%(x))%(240-x); |
|
57 | r=(rand()%(x))%(240-x); | |
58 | h=rand()%(320-y); |
|
58 | h=rand()%(320-y); | |
59 | buf[0]=rand()%(255); |
|
59 | buf[0]=rand()%(255); | |
60 | //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
60 | //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); | |
61 | ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); |
|
61 | ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); | |
62 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
62 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); | |
63 | delay_100us(5000); |
|
63 | delay_100us(5000); | |
64 | //for(volatile int i=0;i<(1024*2);i++); |
|
64 | //for(volatile int i=0;i<(1024*2);i++); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void tryToplay2() |
|
67 | void tryToplay2() | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | extern blkdevice sdcard2blkdev; |
|
70 | extern blkdevice sdcard2blkdev; | |
71 | int i=0,l=0; |
|
71 | int i=0,l=0; | |
72 |
|
72 | |||
73 | spisetspeed(audioCodec0.SPIdev,4000000); |
|
73 | spisetspeed(audioCodec0.SPIdev,4000000); | |
74 | printf("Streaming File\n"); |
|
74 | printf("Streaming File\n"); | |
75 |
|
75 | |||
76 | //printf("New LBA=0x%X\n",nextLba); |
|
76 | //printf("New LBA=0x%X\n",nextLba); | |
77 |
|
77 | |||
78 | while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) |
|
78 | while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | for(i=0;i<512;i+=32) |
|
81 | for(i=0;i<512;i+=32) | |
82 | { |
|
82 | { | |
83 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
83 | vs10XXstream32bytes(&audioCodec0,buffer+i); | |
84 | } |
|
84 | } | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void playFile(ucdirent* file,FAT32fs* part) |
|
88 | void playFile(ucdirent* file,FAT32fs* part) | |
89 | { |
|
89 | { | |
90 | extern volatile vs10XXDev audioCodec0; |
|
90 | extern volatile vs10XXDev audioCodec0; | |
91 | char direntName[]=" \n"; |
|
91 | char direntName[]=" \n"; | |
92 | uint32_t fileLba,nextLba; |
|
92 | uint32_t fileLba,nextLba; | |
93 | int i=0; |
|
93 | int i=0; | |
94 | fat32getdirentname(file,direntName); |
|
94 | fat32getdirentname(file,direntName); | |
95 | //gpioset(LCD_BACKL); |
|
95 | //gpioset(LCD_BACKL); | |
96 | printf("%s\n",direntName); |
|
96 | printf("%s\n",direntName); | |
97 | nextLba=fat32getdirentlba(file); |
|
97 | nextLba=fat32getdirentlba(file); | |
98 | //printf("Streaming File\n"); |
|
98 | //printf("Streaming File\n"); | |
99 | //gpioclr(LCD_BACKL); |
|
99 | //gpioclr(LCD_BACKL); | |
100 | do |
|
100 | do | |
101 | { |
|
101 | { | |
102 | fileLba = nextLba; |
|
102 | fileLba = nextLba; | |
103 | if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) |
|
103 | if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) | |
104 | { |
|
104 | { | |
105 | for(i=0;i<512;i+=32) |
|
105 | for(i=0;i<512;i+=32) | |
106 | { |
|
106 | { | |
107 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
107 | vs10XXstream32bytes(&audioCodec0,buffer+i); | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 | }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); |
|
110 | }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); | |
111 | vs10XXsoftReset(&audioCodec0); |
|
111 | vs10XXsoftReset(&audioCodec0); | |
112 | while (gpiogetval(BP3))delay_100us(1000); |
|
112 | while (gpiogetval(BP3))delay_100us(1000); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void playAllparts() |
|
115 | void playAllparts() | |
116 | { |
|
116 | { | |
117 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; |
|
117 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; | |
118 | ucdirent root; |
|
118 | ucdirent root; | |
119 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) |
|
119 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) | |
120 | { |
|
120 | { | |
121 | printf("Reading on SDCARD2 part1\n"); |
|
121 | printf("Reading on SDCARD2 part1\n"); | |
122 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
122 | if(DIRENT_noErr==fat32getrootfirstent(&root)) | |
123 | { |
|
123 | { | |
124 | do{ |
|
124 | do{ | |
125 | playFile(&root,&sdcard2FAT32part1); |
|
125 | playFile(&root,&sdcard2FAT32part1); | |
126 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
126 | }while (DIRENT_noErr==fat32nextdirent(&root)); | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 | gpioset(LED2); |
|
129 | gpioset(LED2); | |
130 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) |
|
130 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) | |
131 | { |
|
131 | { | |
132 | printf("Reading on SDCARD2 part2\n"); |
|
132 | printf("Reading on SDCARD2 part2\n"); | |
133 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
133 | if(DIRENT_noErr==fat32getrootfirstent(&root)) | |
134 | { |
|
134 | { | |
135 | do{ |
|
135 | do{ | |
136 | playFile(&root,&sdcard2FAT32part2); |
|
136 | playFile(&root,&sdcard2FAT32part2); | |
137 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
137 | }while (DIRENT_noErr==fat32nextdirent(&root)); | |
138 | } |
|
138 | } | |
139 | } |
|
139 | } | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | int main() |
|
142 | int main2() | |
143 | { |
|
143 | { | |
144 | delay_100us(30000); |
|
144 | delay_100us(30000); | |
145 | int i=0; |
|
145 | int i=0; | |
146 | int color=0; |
|
146 | int color=0; | |
147 | // test_all_colors(&lcd0); |
|
147 | // test_all_colors(&lcd0); | |
148 | // test_small_lines(&lcd0); |
|
148 | // test_small_lines(&lcd0); | |
149 | // test_uniform_rw(&lcd0); |
|
149 | // test_uniform_rw(&lcd0); | |
150 |
|
150 | |||
151 | printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD)); |
|
151 | printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD)); | |
152 | printf("LCD ENTRY MODE REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_ENTRYMODE)); |
|
152 | printf("LCD ENTRY MODE REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_ENTRYMODE)); | |
153 | uint16_t test[16]; |
|
153 | uint16_t test[16]; | |
154 | for(int i=0;i<16;i++) |
|
154 | for(int i=0;i<16;i++) | |
155 | { |
|
155 | { | |
156 | test[i]=0xF00F; |
|
156 | test[i]=0xF00F; | |
157 | } |
|
157 | } | |
158 | lcd0.paint(&lcd0,test,10,100,4,4); |
|
158 | lcd0.paint(&lcd0,test,10,100,4,4); | |
159 | lcd0.getPix(&lcd0,test,10,100,4,4); |
|
159 | lcd0.getPix(&lcd0,test,10,100,4,4); | |
160 | for(int i=0;i<16;i++) |
|
160 | for(int i=0;i<16;i++) | |
161 | { |
|
161 | { | |
162 | printf("@%d=0x%X\n",i,test[i]); |
|
162 | printf("@%d=0x%X\n",i,test[i]); | |
163 | } |
|
163 | } | |
164 | // test_lines(&lcd0); |
|
164 | // test_lines(&lcd0); | |
165 |
|
165 | |||
166 | while(1)test_address(&lcd0); |
|
166 | while(1)test_address(&lcd0); | |
167 | for(i=0;i<240;i++) |
|
167 | for(i=0;i<240;i++) | |
168 | { |
|
168 | { | |
169 | if(i>(240/3)) |
|
169 | if(i>(240/3)) | |
170 | { |
|
170 | { | |
171 | color= (i<<5) + 0x1F; |
|
171 | color= (i<<5) + 0x1F; | |
172 | } |
|
172 | } | |
173 | else |
|
173 | else | |
174 | { |
|
174 | { | |
175 | color = i; |
|
175 | color = i; | |
176 | } |
|
176 | } | |
177 | if(i>(2*240/3)) |
|
177 | if(i>(2*240/3)) | |
178 | { |
|
178 | { | |
179 | color= (i<<10) + 0x3FF; |
|
179 | color= (i<<10) + 0x3FF; | |
180 | } |
|
180 | } | |
181 | lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); |
|
181 | lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); | |
182 | } |
|
182 | } | |
183 | while(1)printf("test "); |
|
183 | while(1)printf("test "); | |
184 | // for(i=0;i<240;i++) |
|
184 | // for(i=0;i<240;i++) | |
185 | // { |
|
185 | // { | |
186 | // if(i>(240/3)) |
|
186 | // if(i>(240/3)) | |
187 | // { |
|
187 | // { | |
188 | // color= (i<<5) + 0x1F; |
|
188 | // color= (i<<5) + 0x1F; | |
189 | // } |
|
189 | // } | |
190 | // else |
|
190 | // else | |
191 | // { |
|
191 | // { | |
192 | // color = i; |
|
192 | // color = i; | |
193 | // } |
|
193 | // } | |
194 | // if(i>(2*240/3)) |
|
194 | // if(i>(2*240/3)) | |
195 | // { |
|
195 | // { | |
196 | // color= (i<<10) + 0x3FF; |
|
196 | // color= (i<<10) + 0x3FF; | |
197 | // } |
|
197 | // } | |
198 | // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); |
|
198 | // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); | |
199 | // } |
|
199 | // } | |
200 | for(i=0;i<240;i++) |
|
200 | for(i=0;i<240;i++) | |
201 | { |
|
201 | { | |
202 | ili9328setFrame(&lcd0,i,0,1,100); |
|
202 | ili9328setFrame(&lcd0,i,0,1,100); | |
203 | lcd0.interface->readGRAM(buffer,100); |
|
203 | lcd0.interface->readGRAM(buffer,100); | |
204 | lcd0.paint(&lcd0,buffer,i,200,1,100); |
|
204 | lcd0.paint(&lcd0,buffer,i,200,1,100); | |
205 | } |
|
205 | } | |
206 | while(1); |
|
206 | while(1); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
int main |
|
209 | int main() | |
210 | { |
|
210 | { | |
211 | extern terminal_t terminal0; |
|
211 | extern terminal_t terminal0; | |
212 | extern volatile vs10XXDev audioCodec0; |
|
212 | extern volatile vs10XXDev audioCodec0; | |
213 | printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); |
|
213 | printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); | |
214 | vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); |
|
214 | vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); | |
215 | delay_100us(1000); |
|
215 | delay_100us(1000); | |
216 | vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); |
|
216 | vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); | |
217 | printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); |
|
217 | printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); | |
218 | printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); |
|
218 | printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); | |
219 | //terminal_clear(&terminal0); |
|
219 | //terminal_clear(&terminal0); | |
220 | // gpioclr(LCD_BACKL); |
|
220 | // gpioclr(LCD_BACKL); | |
221 | playAllparts(); |
|
221 | playAllparts(); | |
222 | return 0; |
|
222 | return 0; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 |
|
225 | |||
226 |
|
226 | |||
227 |
|
227 | |||
228 |
|
228 | |||
229 |
|
229 |
@@ -1,13 +1,14 | |||||
1 | TEMPLATE = app |
|
1 | TEMPLATE = app | |
2 | CONFIG += cpu |
|
2 | CONFIG += cpu | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | UCMODEL=simulator |
|
5 | UCMODEL=simulator | |
6 | BSP = SIMULATOR |
|
6 | BSP = SIMULATOR | |
7 |
|
7 | |||
8 | DEFINES += CPUFREQ=100000000 |
|
8 | DEFINES += CPUFREQ=100000000 | |
9 |
|
9 | |||
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | main.c \ |
|
11 | main.c \ | |
12 | test_lcd.c |
|
12 | test_lcd.c \ | |
|
13 | test_SDCARD.c | |||
13 |
|
14 |
@@ -1,71 +1,138 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <bsp.h> |
|
5 | #include <bsp.h> | |
6 | #include <core.h> |
|
6 | #include <core.h> | |
7 | #include <bsp.h> |
|
7 | #include <bsp.h> | |
8 | #include <spi.h> |
|
8 | #include <spi.h> | |
9 | #include <fat32.h> |
|
9 | #include <fat32.h> | |
10 | #include <ucdirent.h> |
|
10 | #include <ucdirent.h> | |
11 | #include <string.h> |
|
11 | #include <string.h> | |
12 | #include <unistd.h> |
|
12 | #include <unistd.h> | |
13 | #include <terminal.h> |
|
13 | #include <terminal.h> | |
14 | #include <stdarg.h> |
|
14 | #include <stdarg.h> | |
15 | #include <malloc.h> |
|
15 | #include <malloc.h> | |
16 |
|
16 | |||
17 | extern streamdevice* __opnfiles__[]; |
|
17 | extern streamdevice* __opnfiles__[]; | |
18 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
18 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); | |
|
19 | extern void test_address(LCD_t* LCD); | |||
|
20 | extern void printRootClustersChain(FAT32fs* sdcard2FAT32part); | |||
19 | char buffer[512]; |
|
21 | char buffer[512]; | |
20 |
|
22 | |||
21 |
|
23 | |||
22 | void streamdevicePrint(streamdevice* dev, const char* format,...) |
|
24 | //void streamdevicePrint(streamdevice* dev, const char* format,...) | |
23 | { |
|
|||
24 | char** str_buffer; |
|
|||
25 | int i; |
|
|||
26 | va_list ap; |
|
|||
27 | va_start(ap,format); |
|
|||
28 | vasprintf(str_buffer,format,ap); |
|
|||
29 | va_end(ap); |
|
|||
30 | i=strlen(*str_buffer); |
|
|||
31 | dev->ops->write(dev,(void*)*str_buffer,1,i); |
|
|||
32 | free(*str_buffer); |
|
|||
33 | } |
|
|||
34 |
|
||||
35 | //int printf(const char *format,...) |
|
|||
36 | //{ |
|
25 | //{ | |
37 |
// char |
|
26 | // char str_buffer[512]=""; | |
38 | // int i; |
|
27 | // int i; | |
39 | // va_list ap; |
|
28 | // va_list ap; | |
40 | // va_start(ap,format); |
|
29 | // va_start(ap,format); | |
41 | // vasprintf(str_buffer,format,ap); |
|
30 | // vasprintf(str_buffer,format,ap); | |
42 | // va_end(ap); |
|
31 | // va_end(ap); | |
43 |
// i=strlen( |
|
32 | // i=strlen(str_buffer); | |
44 |
// |
|
33 | // dev->ops->write(dev,(void*)str_buffer,1,i); | |
45 | // free(*str_buffer); |
|
34 | //} | |
|
35 | ||||
|
36 | int _write(int file, char *ptr, int len) | |||
|
37 | { | |||
|
38 | if(file<__MAX_OPENED_FILES__ && __opnfiles__[file]!=NULL) | |||
|
39 | { | |||
|
40 | if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; | |||
|
41 | } | |||
|
42 | return len; | |||
|
43 | } | |||
46 |
|
44 | |||
|
45 | int _write_r (struct _reent *r, int file, char * ptr, int len) | |||
|
46 | { | |||
|
47 | return _write(file, ptr, len); | |||
|
48 | } | |||
|
49 | ||||
|
50 | //int printf(const char *format,...) | |||
|
51 | //{ | |||
|
52 | // char str_buffer[512]=""; | |||
|
53 | // for(int i =0;i<512;i++)str_buffer[i]='\0'; | |||
|
54 | // int i; | |||
|
55 | // va_list ap; | |||
|
56 | // va_start(ap,format); | |||
|
57 | // vasprintf(str_buffer,format,ap); | |||
|
58 | // va_end(ap); | |||
|
59 | // i=strlen(str_buffer); | |||
|
60 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i); | |||
47 | //} |
|
61 | //} | |
48 |
|
62 | |||
49 | void lcd_print() |
|
63 | void lcd_print() | |
50 | { |
|
64 | { | |
51 | lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); |
|
65 | lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); | |
52 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); |
|
66 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); | |
53 | } |
|
67 | } | |
54 |
|
68 | |||
|
69 | ||||
|
70 | void playFile(ucdirent* file,FAT32fs* part) | |||
|
71 | { | |||
|
72 | extern volatile vs10XXDev audioCodec0; | |||
|
73 | char direntName[]=" \n"; | |||
|
74 | uint32_t fileLba,nextLba; | |||
|
75 | int i=0; | |||
|
76 | fat32getdirentname(file,direntName); | |||
|
77 | //gpioset(LCD_BACKL); | |||
|
78 | printf("%s\n",direntName); | |||
|
79 | nextLba=fat32getdirentlba(file); | |||
|
80 | //printf("Streaming File\n"); | |||
|
81 | //gpioclr(LCD_BACKL); | |||
|
82 | } | |||
|
83 | ||||
|
84 | void listFiles() | |||
|
85 | { | |||
|
86 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; | |||
|
87 | ucdirent root; | |||
|
88 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) | |||
|
89 | { | |||
|
90 | printf("Reading on SDCARD2 part1\n"); | |||
|
91 | if(DIRENT_noErr==fat32getrootfirstent(&root)) | |||
|
92 | { | |||
|
93 | do{ | |||
|
94 | playFile(&root,&sdcard2FAT32part1); | |||
|
95 | }while (DIRENT_noErr==fat32nextdirent(&root)); | |||
|
96 | } | |||
|
97 | } | |||
|
98 | gpioset(LED2); | |||
|
99 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) | |||
|
100 | { | |||
|
101 | printf("Reading on SDCARD2 part2\n"); | |||
|
102 | if(DIRENT_noErr==fat32getrootfirstent(&root)) | |||
|
103 | { | |||
|
104 | do{ | |||
|
105 | playFile(&root,&sdcard2FAT32part2); | |||
|
106 | }while (DIRENT_noErr==fat32nextdirent(&root)); | |||
|
107 | } | |||
|
108 | } | |||
|
109 | } | |||
|
110 | ||||
|
111 | ||||
|
112 | int libuc_main2() | |||
|
113 | { | |||
|
114 | printRootClustersChain(&sdcard2FAT32part1); | |||
|
115 | ||||
|
116 | } | |||
|
117 | ||||
55 | int libuc_main() |
|
118 | int libuc_main() | |
56 | { |
|
119 | { | |
57 | char in[255]; |
|
120 | char in[255]; | |
58 | lcd_print(); |
|
121 | //lcd_print(); | |
59 | printf("hello world\n"); |
|
122 | printf("hello world\n"); | |
60 | streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); |
|
123 | delay_100us(10000); | |
|
124 | // streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); | |||
61 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); |
|
125 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); | |
|
126 | //while(1)test_address(&lcd0); | |||
|
127 | listFiles(); | |||
62 | // while (scanf("%c",in)) |
|
128 | // while (scanf("%c",in)) | |
63 | // { |
|
129 | // { | |
64 | sleep(5); |
|
130 | sleep(5); | |
65 | // } |
|
131 | // } | |
|
132 | ||||
66 | } |
|
133 | } | |
67 |
|
134 | |||
68 |
|
135 | |||
69 |
|
136 | |||
70 |
|
137 | |||
71 |
|
138 |
@@ -1,21 +1,43 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <bsp.h> |
|
5 | #include <bsp.h> | |
6 | #include <core.h> |
|
6 | #include <core.h> | |
7 | #include <VS10XX.h> |
|
7 | #include <VS10XX.h> | |
8 | #include <bsp.h> |
|
8 | #include <bsp.h> | |
9 | #include <spi.h> |
|
9 | #include <spi.h> | |
10 | #include <sdcard.h> |
|
10 | #include <sdcard.h> | |
11 | #include <sdcard-spi.h> |
|
11 | #include <sdcard-spi.h> | |
12 | #include <fat32.h> |
|
12 | #include <fat32.h> | |
13 | #include <ucdirent.h> |
|
13 | #include <ucdirent.h> | |
14 | #include <string.h> |
|
14 | #include <string.h> | |
15 | #include <ili9328.h> |
|
15 | #include <ili9328.h> | |
16 |
|
16 | |||
|
17 | uint16_t buff[50*50]; | |||
17 |
|
18 | |||
18 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) |
|
19 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) | |
19 | { |
|
20 | { | |
20 | // LCD->paintFilRect(LCD,x,y,w,h,0,0,color); |
|
21 | // LCD->paintFilRect(LCD,x,y,w,h,0,0,color); | |
21 | } |
|
22 | } | |
|
23 | int coef=1; | |||
|
24 | ||||
|
25 | void test_address(LCD_t* LCD) | |||
|
26 | { | |||
|
27 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); | |||
|
28 | uint16_t color[1]; | |||
|
29 | for(int y=0;y<320;y++) | |||
|
30 | { | |||
|
31 | for(int x=0;x<240;x++) | |||
|
32 | { | |||
|
33 | color[0]=((x/10*y*x)/((y+x+1)))+coef; | |||
|
34 | coef = color[0]; | |||
|
35 | LCD->paint(LCD,color,x,y,1,1); | |||
|
36 | //delay_100us(100); | |||
|
37 | } | |||
|
38 | } | |||
|
39 | LCD->getPix(LCD,buff,50,50,50,50); | |||
|
40 | // delay_100us(5000); | |||
|
41 | LCD->paint(LCD,buff,50,50,50,50); | |||
|
42 | delay_100us(500); | |||
|
43 | } |
@@ -1,383 +1,336 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 |
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #define FAT32_PRIVATE |
|
22 | #define FAT32_PRIVATE | |
23 | #include <fat32.h> |
|
23 | #include <fat32.h> | |
24 | #include <stdio.h> |
|
24 | #include <stdio.h> | |
25 | #include <stdint.h> |
|
25 | #include <stdint.h> | |
26 | #include <hexviewer.h> |
|
26 | #include <hexviewer.h> | |
27 |
|
27 | |||
28 | char fat32buff[512]__attribute__ ((aligned (4))); |
|
28 | char fat32buff[512]; | |
29 | uint32_t lastSecAddrs=-1; |
|
29 | uint32_t lastSecAddrs=-1; | |
30 | FAT32fs* lastFATFS=0; |
|
30 | FAT32fs* lastFATFS=0; | |
31 |
|
31 | |||
32 | int fat32open(FAT32fs* fs,dikpartition* part) |
|
32 | int fat32open(FAT32fs* fs,dikpartition* part) | |
33 | { |
|
33 | { | |
34 | fs->valide = 0; |
|
34 | //char sector[512]; | |
35 | if(part->valide==0)return FATBadpart; |
|
|||
36 | char sector[512]; |
|
|||
37 | fs->part = part; |
|
35 | fs->part = part; | |
38 | if(!isFat32(fs->part->TypeCode))return FATBadpart; |
|
36 | if(!isFat32(fs->part->TypeCode))return FATBadpart; | |
39 | if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; |
|
37 | //if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr; | |
40 | fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff); |
|
38 | fat32sectorreadout(fs,fs->part->LBABegin); | |
41 |
fs->BPB_ |
|
39 | fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(fat32buff,BPB_BytsPerSecoff); | |
42 |
fs->BPB_ |
|
40 | fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(fat32buff,BPB_RsvdSecCntoff); | |
43 |
fs->BPB_ |
|
41 | fs->BPB_FATSz32 = fat32Ui8_2_Ui32(fat32buff,BPB_FATSz32off); | |
44 | fs->BPB_SecPerClus = sector[BPB_SecPerClusoff]; |
|
42 | fs->BPB_RootClus = fat32Ui8_2_Ui32(fat32buff,BPB_RootClusoff); | |
45 | fs->BPB_NumFATs = sector[BPB_NumFATsoff]; |
|
43 | fs->BPB_SecPerClus = fat32buff[BPB_SecPerClusoff]; | |
|
44 | fs->BPB_NumFATs = fat32buff[BPB_NumFATsoff]; | |||
46 | fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; |
|
45 | fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt; | |
47 | fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); |
|
46 | fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 ); | |
48 | fs->valide=1; |
|
|||
49 | return FATnoErr; |
|
47 | return FATnoErr; | |
50 | } |
|
48 | } | |
51 |
|
49 | |||
52 |
|
50 | |||
53 | int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) |
|
51 | int fat32mkdirent(FAT32fs* fs,ucdirent* dirent) | |
54 | { |
|
52 | { | |
55 |
if |
|
53 | if(fs==0) return DIRENT_BabArg; | |
56 | if(dirent==0) return DIRENT_BabArg; |
|
54 | if(dirent==0) return DIRENT_BabArg; | |
57 | dirent->fs = (UHANDLE)fs; |
|
55 | dirent->fs = (UHANDLE)fs; | |
58 | dirent->getrootfirstent = &fat32getrootfirstent; |
|
56 | dirent->getrootfirstent = &fat32getrootfirstent; | |
59 | dirent->nextdirent = &fat32nextdirent; |
|
57 | dirent->nextdirent = &fat32nextdirent; | |
60 | return DIRENT_noErr; |
|
58 | return DIRENT_noErr; | |
61 | } |
|
59 | } | |
62 |
|
60 | |||
63 |
|
61 | |||
64 | int fat32getrootfirstent(ucdirent* entry) |
|
62 | int fat32getrootfirstent(ucdirent* entry) | |
65 |
{ |
|
63 | { | |
66 | if(entry==0) return DIRENT_BabArg; |
|
64 | if(entry==0) return DIRENT_BabArg; | |
67 | entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; |
|
65 | entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba; | |
68 | entry->Currententry = 0; |
|
66 | entry->Currententry = 0; | |
69 | return fat32nextdirent(entry); |
|
67 | return fat32nextdirent(entry); | |
70 | } |
|
68 | } | |
71 |
|
69 | |||
72 |
|
70 | |||
73 | int fat32getVolName(FAT32fs* fs,char* Name) |
|
71 | int fat32getVolName(FAT32fs* fs,char* Name) | |
74 | { |
|
72 | { | |
75 |
if |
|
73 | if(fs==0) return DIRENT_BabArg; | |
76 | if(Name==0) return DIRENT_BabArg; |
|
74 | if(Name==0) return DIRENT_BabArg; | |
77 | int i=0; |
|
75 | int i=0; | |
78 | ucdirent entry; |
|
76 | ucdirent entry; | |
79 | if(DIRENT_noErr==fat32mkdirent(fs,&entry)) |
|
77 | if(DIRENT_noErr==fat32mkdirent(fs,&entry)) | |
80 | { |
|
78 | { | |
81 | entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba; |
|
79 | entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba; | |
82 | entry.Currententry = -1; |
|
80 | entry.Currententry = -1; | |
83 | if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr; |
|
81 | if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr; | |
84 | for(i=0;i<16;i++) |
|
82 | for(i=0;i<16;i++) | |
85 | { |
|
83 | { | |
86 | Name[i] = entry.DIR_Name[i]; |
|
84 | Name[i] = entry.DIR_Name[i]; | |
87 | } |
|
85 | } | |
88 | return DIRENT_noErr; |
|
86 | return DIRENT_noErr; | |
89 | } |
|
87 | } | |
90 | return DIRENT_ReadErr; |
|
88 | return DIRENT_ReadErr; | |
91 | } |
|
89 | } | |
92 |
|
90 | |||
93 |
|
91 | |||
94 | int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry) |
|
92 | int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry) | |
95 | { |
|
93 | { | |
96 | if(firstentry==0) return DIRENT_BabArg; |
|
94 | if(firstentry==0) return DIRENT_BabArg; | |
97 | if(currententry==0) return DIRENT_BabArg; |
|
95 | if(currententry==0) return DIRENT_BabArg; | |
98 | fat32mkdirent(((FAT32fs*)currententry->fs),firstentry); |
|
96 | fat32mkdirent(((FAT32fs*)currententry->fs),firstentry); | |
99 | firstentry->CurrentSec = fat32getdirentlba(currententry); |
|
97 | firstentry->CurrentSec = fat32getdirentlba(currententry); | |
100 | firstentry->Currententry = -1; |
|
98 | firstentry->Currententry = -1; | |
101 | return fat32nextdirent(firstentry); |
|
99 | return fat32nextdirent(firstentry); | |
102 | } |
|
100 | } | |
103 |
|
101 | |||
104 |
|
102 | |||
105 | int fat32nextdirent(ucdirent* entry) |
|
103 | int fat32nextdirent(ucdirent* entry) | |
106 | { |
|
104 | { | |
107 | uint32_t n=0,res=DIRENT_noErr,k,j; |
|
105 | uint32_t n=0,res=DIRENT_noErr,k,j; | |
108 | k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/ |
|
106 | k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/ | |
109 | j=entry->CurrentSec;// /*Restart at last sector*/ |
|
107 | j=entry->CurrentSec;// /*Restart at last sector*/ | |
110 | do |
|
108 | do | |
111 | { |
|
109 | { | |
112 | //printf("reading new secotr\n",k); |
|
|||
113 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
110 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
114 | //printf("done\n",k); |
|
111 | for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/ | |
115 | /*512 Bytes per sector and 32 bytes per entry*/ |
|
|||
116 | for(k=k;k<(512);k+=32) |
|
|||
117 | { |
|
112 | { | |
118 | if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/ |
|
113 | if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/ | |
119 | { |
|
114 | { | |
120 | //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k])); |
|
|||
121 | if(fat32buff[DIR_Nameoff+k]==(char)0) |
|
115 | if(fat32buff[DIR_Nameoff+k]==(char)0) | |
122 | { |
|
|||
123 | //printf("end of directory reached\n",k); |
|
|||
124 | return DIRENT_EndOfDir; /*0x00 = end of dir*/ |
|
116 | return DIRENT_EndOfDir; /*0x00 = end of dir*/ | |
125 | } |
|
|||
126 | else |
|
117 | else | |
127 | { |
|
118 | if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY))) | |
128 | uint8_t attribute=fat32buff[DIR_Attroff + k]; |
|
|||
129 | if( (attribute==ATTR_DIRECTORY) |
|
|||
130 | ||(attribute==ATTR_ARCHIVE) |
|
|||
131 | ||(attribute==ATTR_READ_ONLY) |
|
|||
132 | ||(attribute==ATTR_READ_ONLY)) |
|
|||
133 | { |
|
119 | { | |
134 | for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; |
|
120 | for(n=0;n<16;n++)entry->DIR_Name[n] = '\0'; | |
135 | for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; |
|
121 | for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k]; | |
136 |
entry->DIR_Attr = |
|
122 | entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k]; | |
137 | entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; |
|
123 | entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k]; | |
138 | entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); |
|
124 | entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k)); | |
139 | entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); |
|
125 | entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k)); | |
140 | entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k)); |
|
126 | entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k)); | |
141 | entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k)); |
|
127 | entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k)); | |
142 | entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k)); |
|
128 | entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k)); | |
143 | entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); |
|
129 | entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k)); | |
144 | entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); |
|
130 | entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k)); | |
145 | entry->CurrentSec = j; |
|
131 | entry->CurrentSec = j; | |
146 |
entry->Currententry = (u |
|
132 | entry->Currententry = (unsigned char)(k/32); | |
147 | return DIRENT_noErr; |
|
133 | return DIRENT_noErr; | |
148 | } |
|
134 | } | |
149 | } |
|
|||
150 | } |
|
135 | } | |
|
136 | ||||
151 | } |
|
137 | } | |
152 | //printf("asking for next sector\n"); |
|
|||
153 | //printf("current = 0x%X\n",j); |
|
|||
154 | j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); |
|
138 | j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k); | |
155 | //printf("got it 0x%x\n",k); |
|
|||
156 | if(j!=DIRENT_noErr) |
|
139 | if(j!=DIRENT_noErr) | |
157 | { |
|
140 | { | |
158 | if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ |
|
141 | if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/ | |
159 | return j; |
|
142 | return j; | |
160 | } |
|
143 | } | |
161 | j=k; |
|
144 | j=k; | |
162 | k=0; |
|
145 | k=0; | |
163 | }while(res==DIRENT_noErr); |
|
146 | }while(res==DIRENT_noErr); | |
164 | return res; |
|
147 | return res; | |
165 | } |
|
148 | } | |
166 |
|
149 | |||
167 |
|
150 | |||
168 | int fat32getdirentname(ucdirent* entry,char* nameBuffer) |
|
151 | int fat32getdirentname(ucdirent* entry,char* nameBuffer) | |
169 | { |
|
152 | { | |
170 | uint32_t j; |
|
153 | uint32_t j; | |
171 | int k,n,i; |
|
154 | int k,n,i; | |
172 | int res=DIRENT_noErr; |
|
155 | int res=DIRENT_noErr; | |
173 | char longName=0; |
|
156 | char longName=0; | |
174 | k=(((signed char)entry->Currententry))*32; |
|
157 | k=(((signed char)entry->Currententry))*32; | |
175 | j=entry->CurrentSec; |
|
158 | j=entry->CurrentSec; | |
176 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
159 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
177 | longName |= fat32buff[DIR_Nameoff + 6 + k]=='~'; |
|
160 | longName |= fat32buff[DIR_Nameoff + 6 + k]=='~'; | |
178 | if(k>=32) |
|
161 | if(k>=32) | |
179 | { |
|
162 | { | |
180 | longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME); |
|
163 | longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME); | |
181 | } |
|
164 | } | |
182 | else |
|
165 | else | |
183 | { |
|
166 | { | |
184 | uint32_t j_old=j; |
|
167 | uint32_t j_old=j; | |
185 | if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; |
|
168 | if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; | |
186 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
169 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
187 | k=512; |
|
170 | k=512; | |
188 | longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME); |
|
171 | longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME); | |
189 | if(!longName) |
|
172 | if(!longName) | |
190 | { |
|
173 | { | |
191 | k=0; |
|
174 | k=0; | |
192 | j=j_old; |
|
175 | j=j_old; | |
193 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
176 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
194 | k=0; |
|
177 | k=0; | |
195 | } |
|
178 | } | |
196 | } |
|
179 | } | |
197 | if(longName) //long Name? or lower case name |
|
180 | if(longName) //long Name? or lower case name | |
198 | { |
|
181 | { | |
199 | i=0; |
|
182 | i=0; | |
200 | do{ |
|
183 | do{ | |
201 | if(k==0) |
|
184 | if(k==0) | |
202 | { |
|
185 | { | |
203 | //get previous sector |
|
186 | //get previous sector | |
204 |
if(fat32prevsectorlba |
|
187 | if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr; | |
205 | fat32sectorreadout(((FAT32fs*)entry->fs),j); |
|
188 | fat32sectorreadout(((FAT32fs*)entry->fs),j); | |
206 | k=512-32; |
|
189 | k=512-32; | |
207 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; |
|
190 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; | |
208 | for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k]; |
|
191 | for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k]; | |
209 | for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k]; |
|
192 | for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k]; | |
210 | } |
|
193 | } | |
211 | else |
|
194 | else | |
212 | { |
|
195 | { | |
213 | k-=32; |
|
196 | k-=32; | |
214 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; |
|
197 | for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k]; | |
215 | for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k]; |
|
198 | for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k]; | |
216 | for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k]; |
|
199 | for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k]; | |
217 | } |
|
200 | } | |
218 | }while((fat32buff[k]&0x40)!=0x40); |
|
201 | }while((fat32buff[k]&0x40)!=0x40); | |
219 | nameBuffer[i]='\0'; |
|
202 | nameBuffer[i]='\0'; | |
220 | } |
|
203 | } | |
221 | else |
|
204 | else | |
222 | { |
|
205 | { | |
223 | i=0; |
|
206 | i=0; | |
224 | for(n=0;n<8;n++) |
|
207 | for(n=0;n<8;n++) | |
225 | { |
|
208 | { | |
226 | nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k]; |
|
209 | nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k]; | |
227 | if(nameBuffer[i]!=0x20)i++; |
|
210 | if(nameBuffer[i]!=0x20)i++; | |
228 | } |
|
211 | } | |
229 | if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20)) |
|
212 | if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20)) | |
230 | nameBuffer[i++]='.'; |
|
213 | nameBuffer[i++]='.'; | |
231 | for(n=8;n<11;n++) |
|
214 | for(n=8;n<11;n++) | |
232 | { |
|
215 | { | |
233 | nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k]; |
|
216 | nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k]; | |
234 | if(nameBuffer[i]!=0x20)i++; |
|
217 | if(nameBuffer[i]!=0x20)i++; | |
235 | } |
|
218 | } | |
236 |
|
219 | |||
237 | nameBuffer[i]='\0'; |
|
220 | nameBuffer[i]='\0'; | |
238 | } |
|
221 | } | |
239 | return res; |
|
222 | return res; | |
240 | } |
|
223 | } | |
241 |
|
224 | |||
242 |
|
225 | |||
243 | uint32_t fat32getdirentlba(ucdirent* entry) |
|
226 | uint32_t fat32getdirentlba(ucdirent* entry) | |
244 | { |
|
227 | { | |
245 | uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16); |
|
228 | uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16); | |
246 | uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum); |
|
229 | uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum); | |
247 | return lba; |
|
230 | return lba; | |
248 | } |
|
231 | } | |
249 |
|
232 | |||
250 |
|
233 | |||
251 | int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) |
|
234 | int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) | |
252 | { |
|
235 | { | |
253 |
|
236 | |||
254 | if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/ |
|
237 | if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/ | |
255 | { |
|
238 | { | |
256 | *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/ |
|
239 | *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/ | |
257 | return DIRENT_noErr; |
|
240 | return DIRENT_noErr; | |
258 | } |
|
241 | } | |
259 |
|
242 | |||
260 | uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ |
|
243 | uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | |
261 | uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ |
|
244 | uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ | |
262 | fat32sectorreadout(fs,fatsec); |
|
245 | fat32sectorreadout(fs,fatsec); | |
263 | int i= fat32clusterinfatoff(clusternum); |
|
246 | int i= fat32clusterinfatoff(clusternum); | |
264 | *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); |
|
247 | *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); | |
265 | if(*nextsector_lba==0xFFFFFFF7) |
|
248 | if(*nextsector_lba==0xFFFFFFF7) | |
266 | { |
|
249 | { | |
|
250 | ||||
|
251 | printf("DIRENT_BadSect\n"); | |||
267 | return DIRENT_BadSect; |
|
252 | return DIRENT_BadSect; | |
268 | } |
|
253 | } | |
269 | if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) |
|
254 | if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) | |
270 | { |
|
255 | { | |
|
256 | printf("DIRENT_LastSect\n"); | |||
271 | return DIRENT_LastSect; |
|
257 | return DIRENT_LastSect; | |
272 | } |
|
258 | } | |
273 | *nextsector_lba = clusterlba(fs,*nextsector_lba); |
|
259 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |
274 | return DIRENT_noErr; |
|
260 | return DIRENT_noErr; | |
275 | } |
|
261 | } | |
276 |
|
262 | |||
277 |
|
263 | |||
278 | int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) |
|
264 | int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba) | |
279 | { |
|
265 | { | |
280 | uint32_t i=0,fatsec=0; |
|
266 | uint32_t i=0,fatsec=0; | |
281 |
if(((lastsector_lba - |
|
267 | if(((lastsector_lba - fs->cluster_begin_lba) % (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ | |
282 | { |
|
268 | { | |
283 | *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ |
|
269 | *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ | |
284 | return DIRENT_noErr; |
|
270 | return DIRENT_noErr; | |
285 | } |
|
271 | } | |
286 |
|
272 | uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | ||
287 | uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ |
|
|||
288 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ |
|
273 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ | |
289 | while(fatsec>=fs->fat_begin_lba) |
|
274 | do | |
290 | { |
|
275 | { | |
|
276 | ||||
291 | fat32sectorreadout(fs,fatsec); |
|
277 | fat32sectorreadout(fs,fatsec); | |
292 | fatsec--; |
|
278 | fatsec--; | |
293 |
for(i=5 |
|
279 | for(i=511;i>3;i-=4) | |
294 | { |
|
280 | { | |
295 | *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i); |
|
281 | *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3); | |
296 | if (*nextsector_lba ==clusternum) |
|
282 | if (*nextsector_lba ==clusternum) | |
297 | { |
|
283 | { | |
298 | *nextsector_lba = clusterlba(fs,*nextsector_lba); |
|
284 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |
299 | return DIRENT_noErr; |
|
285 | return DIRENT_noErr; | |
300 | } |
|
286 | } | |
|
287 | ||||
301 | } |
|
288 | } | |
302 | } |
|
289 | ||
|
290 | }while(fatsec>=fs->fat_begin_lba); | |||
303 |
|
291 | |||
304 | clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ |
|
292 | clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ | |
305 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ |
|
293 | fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/ | |
306 | do |
|
294 | do | |
307 | { |
|
295 | { | |
308 |
|
296 | |||
309 | fat32sectorreadout(fs,fatsec); |
|
297 | fat32sectorreadout(fs,fatsec); | |
310 | fatsec++; |
|
298 | fatsec++; | |
311 | for(i=0;i<512;i+=4) |
|
299 | for(i=0;i<512;i+=4) | |
312 | { |
|
300 | { | |
313 | *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i); |
|
301 | *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i); | |
314 | if (*nextsector_lba ==clusternum) |
|
302 | if (*nextsector_lba ==clusternum) | |
315 | { |
|
303 | { | |
316 | *nextsector_lba = clusterlba(fs,*nextsector_lba); |
|
304 | *nextsector_lba = clusterlba(fs,*nextsector_lba); | |
317 | return DIRENT_noErr; |
|
305 | return DIRENT_noErr; | |
318 | } |
|
306 | } | |
319 |
|
307 | |||
320 | } |
|
308 | } | |
|
309 | ||||
321 | }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); |
|
310 | }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)); | |
322 | return DIRENT_ReadErr; |
|
311 | return DIRENT_ReadErr; | |
323 | } |
|
312 | } | |
324 |
|
313 | |||
325 |
|
314 | |||
326 | int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba) |
|
|||
327 | { |
|
|||
328 | uint32_t i=0,fatsec=0; |
|
|||
329 | if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/ |
|
|||
330 | { |
|
|||
331 | *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/ |
|
|||
332 | return DIRENT_noErr; |
|
|||
333 | } |
|
|||
334 |
|
||||
335 | uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/ |
|
|||
336 | uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry))); |
|
|||
337 | fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ |
|
|||
338 | *nextsector_lba = fat32getdirentlba(entry); |
|
|||
339 | while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32)) |
|
|||
340 | { |
|
|||
341 | uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba)); |
|
|||
342 | fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/ |
|
|||
343 | fat32sectorreadout(fs,fatsec); |
|
|||
344 | i= fat32clusterinfatoff(currentClusternum); |
|
|||
345 | if(i==clusternum) |
|
|||
346 | { |
|
|||
347 | return DIRENT_noErr; |
|
|||
348 | } |
|
|||
349 | *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i); |
|
|||
350 | if(*nextsector_lba==0xFFFFFFF7) |
|
|||
351 | { |
|
|||
352 | return DIRENT_BadSect; |
|
|||
353 | } |
|
|||
354 | if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6) |
|
|||
355 | { |
|
|||
356 | return DIRENT_LastSect; |
|
|||
357 | } |
|
|||
358 | } |
|
|||
359 | return DIRENT_ReadErr; |
|
|||
360 | } |
|
|||
361 |
|
||||
362 |
|
||||
363 |
|
315 | |||
364 |
|
316 | |||
365 |
|
317 | |||
366 |
|
318 | |||
367 |
|
319 | |||
368 |
|
320 | |||
369 |
|
321 | |||
370 |
|
322 | |||
371 |
|
323 | |||
372 |
|
324 | |||
373 |
|
325 | |||
374 |
|
326 | |||
375 |
|
327 | |||
376 |
|
328 | |||
377 |
|
329 | |||
378 |
|
330 | |||
379 |
|
331 | |||
380 |
|
332 | |||
381 |
|
333 | |||
382 |
|
334 | |||
383 |
|
335 | |||
|
336 |
@@ -1,86 +1,86 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include <mbr.h> |
|
22 | #include <mbr.h> | |
23 | #include <stdio.h> |
|
23 | #include <stdio.h> | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | int mbropen(blkdevice* phy,dikpartition* part,char partNum) |
|
26 | int mbropen(blkdevice* phy,dikpartition* part,char partNum) | |
27 | { |
|
27 | { | |
28 | printf("enter MBR open function\n"); |
|
28 | printf("enter MBR open function\n"); | |
29 | char mbr[512]; |
|
29 | char mbr[512]; | |
30 | if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg; |
|
30 | if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg; | |
31 | part->phy = phy; |
|
31 | part->phy = phy; | |
32 | if(phy->read(phy,mbr,0,1)!=RES_OK) |
|
32 | if(phy->read(phy,mbr,0,1)!=RES_OK) | |
33 | { |
|
33 | { | |
34 | printf("can't read MBR!\n"); |
|
34 | printf("can't read MBR!\n"); | |
35 | printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]); |
|
35 | printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]); | |
36 | part->valide = 0; |
|
36 | part->valide = 0; | |
37 | return MBRReadErr; |
|
37 | return MBRReadErr; | |
38 | } |
|
38 | } | |
39 | if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) |
|
39 | if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) | |
40 | { |
|
40 | { | |
41 |
|
|
41 | part->TypeCode = mbr[(512-82+TypeCodeoffset)+(partNum*16)]; | |
42 | part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24); |
|
42 | part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+(partNum*16)]<<24); | |
43 | part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24); |
|
43 | part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+(partNum*16)]<<24); | |
44 | printf("MBR Ok\n"); |
|
44 | printf("MBR Ok\n"); | |
45 | part->valide = 1; |
|
45 | part->valide = 1; | |
46 | return MBRnoErr; |
|
46 | return MBRnoErr; | |
47 | } |
|
47 | } | |
48 | printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]); |
|
48 | printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]); | |
49 | part->valide = 0; |
|
49 | part->valide = 0; | |
50 | return MBRBadMbr; |
|
50 | return MBRBadMbr; | |
51 |
|
51 | |||
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 |
|
55 | |||
56 |
|
56 | |||
57 |
|
57 | |||
58 |
|
58 | |||
59 |
|
59 | |||
60 |
|
60 | |||
61 |
|
61 | |||
62 |
|
62 | |||
63 |
|
63 | |||
64 |
|
64 | |||
65 |
|
65 | |||
66 |
|
66 | |||
67 |
|
67 | |||
68 |
|
68 | |||
69 |
|
69 | |||
70 |
|
70 | |||
71 |
|
71 | |||
72 |
|
72 | |||
73 |
|
73 | |||
74 |
|
74 | |||
75 |
|
75 | |||
76 |
|
76 | |||
77 |
|
77 | |||
78 |
|
78 | |||
79 |
|
79 | |||
80 |
|
80 | |||
81 |
|
81 | |||
82 |
|
82 | |||
83 |
|
83 | |||
84 |
|
84 | |||
85 |
|
85 | |||
86 |
|
86 |
@@ -1,239 +1,239 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2013, Alexis Jeandet |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include <widget.h> |
|
22 | #include <widget.h> | |
23 | #include <terminal.h> |
|
23 | #include <terminal.h> | |
24 | #include <stdint.h> |
|
24 | #include <stdint.h> | |
25 | #include <stdio.h> |
|
25 | #include <stdio.h> | |
26 | #include <gpio.h> |
|
26 | #include <gpio.h> | |
27 | #include <core.h> |
|
27 | #include <core.h> | |
28 | #include <malloc.h> |
|
28 | #include <malloc.h> | |
29 |
|
29 | |||
30 | #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) |
|
30 | #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) | |
31 | #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) |
|
31 | #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) | |
32 |
|
32 | |||
33 | streamdevice_ops TERMINAL_OPS= |
|
33 | streamdevice_ops TERMINAL_OPS= | |
34 | { |
|
34 | { | |
35 | .write = &terminal_write, |
|
35 | .write = &terminal_write, | |
36 | .read = &terminal_read, |
|
36 | .read = &terminal_read, | |
37 | .setpos= &terminal_setpos, |
|
37 | .setpos= &terminal_setpos, | |
38 | .close = NULL |
|
38 | .close = NULL | |
39 | }; |
|
39 | }; | |
40 |
|
40 | |||
41 | int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev) |
|
41 | int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev) | |
42 | { |
|
42 | { | |
43 | if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL)) |
|
43 | if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL)) | |
44 | { |
|
44 | { | |
45 | terminal->LCD=LCD; |
|
45 | terminal->LCD=LCD; | |
46 | terminal->font=font; |
|
46 | terminal->font=font; | |
47 | terminal->line = 0; |
|
47 | terminal->line = 0; | |
48 | terminal->column = 0; |
|
48 | terminal->column = 0; | |
49 | terminal->horizontalSpace = 0; |
|
49 | terminal->horizontalSpace = 0; | |
50 | terminal->verticalSpace = 0; |
|
50 | terminal->verticalSpace = 0; | |
51 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
51 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
52 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
52 | int charh=terminal->font->Height + terminal->verticalSpace; | |
53 | terminal->textColor=0xFFFF; |
|
53 | terminal->textColor=0xFFFF; | |
54 | terminal->backgroundColor=0xF00F; |
|
54 | terminal->backgroundColor=0xF00F; | |
55 | terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10)); |
|
55 | terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10)); | |
56 | strdev->_stream = (UHANDLE)terminal; |
|
56 | strdev->_stream = (UHANDLE)terminal; | |
57 | strdev->ops = &TERMINAL_OPS; |
|
57 | strdev->ops = &TERMINAL_OPS; | |
58 | strdev->streamPt = 0; |
|
58 | strdev->streamPt = 0; | |
59 | terminal_clear(terminal); |
|
59 | terminal_clear(terminal); | |
60 | terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
60 | terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
61 | terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1)); |
|
61 | terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1)); | |
62 | terminal->firstLine = 0; |
|
62 | terminal->firstLine = 0; | |
63 | terminal->lastLine = 0; |
|
63 | terminal->lastLine = 0; | |
64 | terminal->empty = 1; |
|
64 | terminal->empty = 1; | |
65 | for(int i=1;i<=terminal->lineCount;i++) |
|
65 | for(int i=1;i<=terminal->lineCount;i++) | |
66 | { |
|
66 | { | |
67 | terminal->buffer[i * terminal->columnCount]='\n'; |
|
67 | terminal->buffer[i * terminal->columnCount]='\n'; | |
68 | } |
|
68 | } | |
69 | return 1; |
|
69 | return 1; | |
70 | } |
|
70 | } | |
71 | return 0; |
|
71 | return 0; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height) |
|
74 | void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height) | |
75 | { |
|
75 | { | |
76 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
76 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
77 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
77 | int charh=terminal->font->Height + terminal->verticalSpace; | |
78 | if(terminal->LCD->height<(Ypos+height)) |
|
78 | if(terminal->LCD->height<(Ypos+height)) | |
79 | return; |
|
79 | return; | |
80 | if(terminal->LCD->width<(Xpos+width)) |
|
80 | if(terminal->LCD->width<(Xpos+width)) | |
81 | return; |
|
81 | return; | |
82 | terminal->Xpos = Xpos; |
|
82 | terminal->Xpos = Xpos; | |
83 | terminal->Ypos = Ypos; |
|
83 | terminal->Ypos = Ypos; | |
84 | terminal->height = height; |
|
84 | terminal->height = height; | |
85 | terminal->width = width; |
|
85 | terminal->width = width; | |
86 | terminal->lineCount = terminal->height/charh; |
|
86 | terminal->lineCount = terminal->height/charh; | |
87 | terminal->columnCount = (terminal->width/charw)-1; |
|
87 | terminal->columnCount = (terminal->width/charw)-1; | |
88 | terminal_clear(terminal); |
|
88 | terminal_clear(terminal); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 |
|
91 | |||
92 | void terminal_clear(terminal_t* terminal) |
|
92 | void terminal_clear(terminal_t* terminal) | |
93 | { |
|
93 | { | |
94 | terminal->firstLine = 0; |
|
94 | terminal->firstLine = 0; | |
95 | terminal->lastLine = 0; |
|
95 | terminal->lastLine = 0; | |
96 | terminal->empty = 1; |
|
96 | terminal->empty = 1; | |
97 | terminal->line =0; |
|
97 | terminal->line =0; | |
98 | terminal->column=0; |
|
98 | terminal->column=0; | |
99 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor); |
|
99 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor) |
|
102 | void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor) | |
103 | { |
|
103 | { | |
104 | terminal->backgroundColor = backgrooundColor; |
|
104 | terminal->backgroundColor = backgrooundColor; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void terminal_settextColor(terminal_t* terminal, uint32_t textColor) |
|
107 | void terminal_settextColor(terminal_t* terminal, uint32_t textColor) | |
108 | { |
|
108 | { | |
109 | terminal->textColor = textColor; |
|
109 | terminal->textColor = textColor; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | void terminal_movecursor(terminal_t* terminal,int n) |
|
113 | void terminal_movecursor(terminal_t* terminal,int n) | |
114 | { |
|
114 | { | |
115 | terminal->column += n; |
|
115 | terminal->column += n; | |
116 | if(terminal->column>(terminal->columnCount)) |
|
116 | if(terminal->column>(terminal->columnCount)) | |
117 | { |
|
117 | { | |
118 | terminal->line += (terminal->column)/terminal->columnCount; |
|
118 | terminal->line += (terminal->column)/terminal->columnCount; | |
119 | terminal->line = terminal->line % terminal->lineCount; |
|
119 | terminal->line = terminal->line % terminal->lineCount; | |
120 | terminal->column = (terminal->column % terminal->columnCount)-1; |
|
120 | terminal->column = (terminal->column % terminal->columnCount)-1; | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void terminal_clearCurentLine(terminal_t* terminal) |
|
124 | void terminal_clearCurentLine(terminal_t* terminal) | |
125 | { |
|
125 | { | |
126 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
126 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
127 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
127 | int charh=terminal->font->Height + terminal->verticalSpace; | |
128 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
128 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | int terminal_writenc(terminal_t* terminal,char* data, int n) |
|
131 | int terminal_writenc(terminal_t* terminal,char* data, int n) | |
132 | { |
|
132 | { | |
133 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
133 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
134 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
134 | int charh=terminal->font->Height + terminal->verticalSpace; | |
135 | int l=0; |
|
135 | int l=0; | |
136 | char buffer[2]=" "; |
|
136 | char buffer[2]=" "; | |
137 | while(l<n) |
|
137 | while(l<n) | |
138 | { |
|
138 | { | |
139 |
|
139 | |||
140 | buffer[0]=data[l]; |
|
140 | buffer[0]=data[l]; | |
141 | if(buffer[0]=='\n') |
|
141 | if(buffer[0]=='\n') | |
142 | { |
|
142 | { | |
143 | terminal->line= (terminal->line+1) % terminal->lineCount; |
|
143 | terminal->line= (terminal->line+1) % terminal->lineCount; | |
144 | terminal->column = 0; |
|
144 | terminal->column = 0; | |
145 | if(terminal->line==0) |
|
145 | if(terminal->line==0) | |
146 | terminal_clear(terminal); |
|
146 | terminal_clear(terminal); | |
147 | else |
|
147 | else | |
148 | terminal_clearCurentLine(terminal); |
|
148 | terminal_clearCurentLine(terminal); | |
149 | }else { |
|
149 | }else { | |
150 | if(buffer[0]=='\t') |
|
150 | if(buffer[0]=='\t') | |
151 | { |
|
151 | { | |
152 | for(int i=0;i<1;i++)terminal_movecursor(terminal,1); |
|
152 | for(int i=0;i<1;i++)terminal_movecursor(terminal,1); | |
153 | }else |
|
153 | }else | |
154 | if(terminal->column==0)terminal_clearCurentLine(terminal); |
|
154 | if(terminal->column==0)terminal_clearCurentLine(terminal); | |
155 | if(buffer[0]!='\r'){ |
|
155 | if(buffer[0]!='\r'){ | |
156 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
156 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
157 |
|
|
157 | terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
158 | #include <ili9328.h> |
|
158 | //#include <ili9328.h> | |
159 | ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); |
|
159 | // ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
160 | terminal_movecursor(terminal,1); |
|
160 | terminal_movecursor(terminal,1); | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 | l++; |
|
163 | l++; | |
164 | } |
|
164 | } | |
165 | return n; |
|
165 | return n; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void terminal_print_line(terminal_t* terminal,int line) |
|
168 | void terminal_print_line(terminal_t* terminal,int line) | |
169 | { |
|
169 | { | |
170 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
170 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
171 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
171 | int charh=terminal->font->Height + terminal->verticalSpace; | |
172 | terminal_clearCurentLine(terminal); |
|
172 | terminal_clearCurentLine(terminal); | |
173 | terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); |
|
173 | terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | int terminal_writenc2(terminal_t* terminal,char* data, int n) |
|
176 | int terminal_writenc2(terminal_t* terminal,char* data, int n) | |
177 | { |
|
177 | { | |
178 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
178 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
179 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
179 | int charh=terminal->font->Height + terminal->verticalSpace; | |
180 | /* First copy to buffer*/ |
|
180 | /* First copy to buffer*/ | |
181 | int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column; |
|
181 | int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column; | |
182 | for(int i=0;i<n;i++) |
|
182 | for(int i=0;i<n;i++) | |
183 | { |
|
183 | { | |
184 | terminal->empty=0; |
|
184 | terminal->empty=0; | |
185 | terminal->buffer[offset] = data[i]; |
|
185 | terminal->buffer[offset] = data[i]; | |
186 | if(data[i]=='\n') |
|
186 | if(data[i]=='\n') | |
187 | { |
|
187 | { | |
188 | offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1)); |
|
188 | offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1)); | |
189 | } |
|
189 | } | |
190 | else |
|
190 | else | |
191 | { |
|
191 | { | |
192 | offset++; |
|
192 | offset++; | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 | if(!terminal->empty) |
|
195 | if(!terminal->empty) | |
196 | { |
|
196 | { | |
197 | for(int i=terminal->firstLine;i<=terminal->lastLine;i++) |
|
197 | for(int i=terminal->firstLine;i<=terminal->lastLine;i++) | |
198 | { |
|
198 | { | |
199 | terminal_print_line(terminal,i); |
|
199 | terminal_print_line(terminal,i); | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 | return n; |
|
202 | return n; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 |
|
205 | |||
206 |
|
206 | |||
207 | int terminal_write(streamdevice* device,void* data,int size, int n) |
|
207 | int terminal_write(streamdevice* device,void* data,int size, int n) | |
208 | { |
|
208 | { | |
209 | return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n); |
|
209 | return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | int terminal_read(streamdevice* device,void* data,int size, int n) |
|
212 | int terminal_read(streamdevice* device,void* data,int size, int n) | |
213 | { |
|
213 | { | |
214 | return n*size; |
|
214 | return n*size; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | int terminal_setpos(streamdevice* device,int pos) |
|
217 | int terminal_setpos(streamdevice* device,int pos) | |
218 | { |
|
218 | { | |
219 | return 1; |
|
219 | return 1; | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | int terminal_close( streamdevice* device) |
|
222 | int terminal_close( streamdevice* device) | |
223 | { |
|
223 | { | |
224 | return 1; |
|
224 | return 1; | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 |
|
227 | |||
228 |
|
228 | |||
229 |
|
229 | |||
230 |
|
230 | |||
231 |
|
231 | |||
232 |
|
232 | |||
233 |
|
233 | |||
234 |
|
234 | |||
235 |
|
235 | |||
236 |
|
236 | |||
237 |
|
237 | |||
238 |
|
238 | |||
239 |
|
239 |
@@ -1,196 +1,195 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 |
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef FAT32_H |
|
22 | #ifndef FAT32_H | |
23 | #define FAT32_H |
|
23 | #define FAT32_H | |
24 | #include <mbr.h> |
|
24 | #include <mbr.h> | |
25 | #include <libucfs.h> |
|
25 | #include <libucfs.h> | |
26 | #include <ucdirent.h> |
|
26 | #include <ucdirent.h> | |
27 | #include <stdint.h> |
|
27 | #include <stdint.h> | |
28 | #include <stdint-gcc.h> |
|
28 | #include <stdint-gcc.h> | |
29 | /*BPB (Boot Sector) Offsets */ |
|
29 | /*BPB (Boot Sector) Offsets */ | |
30 |
|
30 | |||
31 | #define BS_jmpBootoff 0 |
|
31 | #define BS_jmpBootoff 0 | |
32 | #define BS_OEMNameoff 3 |
|
32 | #define BS_OEMNameoff 3 | |
33 | #define BPB_BytsPerSecoff 11 |
|
33 | #define BPB_BytsPerSecoff 11 | |
34 | #define BPB_SecPerClusoff 13 |
|
34 | #define BPB_SecPerClusoff 13 | |
35 | #define BPB_RsvdSecCntoff 14 |
|
35 | #define BPB_RsvdSecCntoff 14 | |
36 | #define BPB_NumFATsoff 16 |
|
36 | #define BPB_NumFATsoff 16 | |
37 | #define BPB_RootEntCntoff 17 |
|
37 | #define BPB_RootEntCntoff 17 | |
38 | #define BPB_TotSec16off 19 |
|
38 | #define BPB_TotSec16off 19 | |
39 | #define BPB_Mediaoff 21 |
|
39 | #define BPB_Mediaoff 21 | |
40 | #define BPB_FATSz16off 22 |
|
40 | #define BPB_FATSz16off 22 | |
41 | #define BPB_SecPerTrkoff 24 |
|
41 | #define BPB_SecPerTrkoff 24 | |
42 | #define BPB_NumHeadsoff 26 |
|
42 | #define BPB_NumHeadsoff 26 | |
43 | #define BPB_HiddSecoff 28 |
|
43 | #define BPB_HiddSecoff 28 | |
44 | #define BPB_TotSec32off 32 |
|
44 | #define BPB_TotSec32off 32 | |
45 | /*FAT16*/ |
|
45 | /*FAT16*/ | |
46 | #define BS_DrvNumFAT16off 36 |
|
46 | #define BS_DrvNumFAT16off 36 | |
47 | #define BS_Reserved1FAT16off 37 |
|
47 | #define BS_Reserved1FAT16off 37 | |
48 | #define BS_BootSigFAT16off 38 |
|
48 | #define BS_BootSigFAT16off 38 | |
49 | #define BS_VolIDFAT16off 39 |
|
49 | #define BS_VolIDFAT16off 39 | |
50 | #define BS_VolLabFAT16off 43 |
|
50 | #define BS_VolLabFAT16off 43 | |
51 | #define BS_FilSysTypeFAT16off 54 |
|
51 | #define BS_FilSysTypeFAT16off 54 | |
52 | /*FAT32*/ |
|
52 | /*FAT32*/ | |
53 | #define BPB_FATSz32off 36 |
|
53 | #define BPB_FATSz32off 36 | |
54 | #define BPB_ExtFlagsoff 40 |
|
54 | #define BPB_ExtFlagsoff 40 | |
55 | #define BPB_FSVeroff 42 |
|
55 | #define BPB_FSVeroff 42 | |
56 | #define BPB_RootClusoff 44 |
|
56 | #define BPB_RootClusoff 44 | |
57 | #define BPB_FSInfooff 48 |
|
57 | #define BPB_FSInfooff 48 | |
58 | #define BPB_BkBootSecoff 50 |
|
58 | #define BPB_BkBootSecoff 50 | |
59 | #define BPB_Reservedoff 52 |
|
59 | #define BPB_Reservedoff 52 | |
60 | #define BS_DrvNumFAT32off 64 |
|
60 | #define BS_DrvNumFAT32off 64 | |
61 | #define BS_Reserved1FAT32off 65 |
|
61 | #define BS_Reserved1FAT32off 65 | |
62 | #define BS_BootSigFAT32off 66 |
|
62 | #define BS_BootSigFAT32off 66 | |
63 | #define BS_VolIDFAT32off 67 |
|
63 | #define BS_VolIDFAT32off 67 | |
64 | #define BS_VolLabFAT32off 71 |
|
64 | #define BS_VolLabFAT32off 71 | |
65 | #define BS_FilSysTypeFAT32off 82 |
|
65 | #define BS_FilSysTypeFAT32off 82 | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | #define DIR_Nameoff 0 |
|
68 | #define DIR_Nameoff 0 | |
69 | #define DIR_Attroff 0xb |
|
69 | #define DIR_Attroff 0xb | |
70 | #define DIR_FstClusHIoff 0x14 |
|
70 | #define DIR_FstClusHIoff 0x14 | |
71 | #define DIR_FstClusLOoff 0x1A |
|
71 | #define DIR_FstClusLOoff 0x1A | |
72 | #define DIR_FileSizeoff 0x1c |
|
72 | #define DIR_FileSizeoff 0x1c | |
73 | #define DIR_CrtTimeTenthoff 13 |
|
73 | #define DIR_CrtTimeTenthoff 13 | |
74 | #define DIR_CrtTimeoff 14 |
|
74 | #define DIR_CrtTimeoff 14 | |
75 | #define DIR_CrtDateoff 16 |
|
75 | #define DIR_CrtDateoff 16 | |
76 | #define DIR_LstAccDateoff 18 |
|
76 | #define DIR_LstAccDateoff 18 | |
77 | #define DIR_WrtTimeoff 22 |
|
77 | #define DIR_WrtTimeoff 22 | |
78 | #define DIR_WrtDateoff 24 |
|
78 | #define DIR_WrtDateoff 24 | |
79 |
|
79 | |||
80 |
|
80 | |||
81 |
|
81 | |||
82 | #define FATBadpart 1 |
|
82 | #define FATBadpart 1 | |
83 | #define FATBabArg 2 |
|
83 | #define FATBabArg 2 | |
84 | #define FATReadErr 3 |
|
84 | #define FATReadErr 3 | |
85 | #define FATnoErr 0 |
|
85 | #define FATnoErr 0 | |
86 |
|
86 | |||
87 | /* |
|
87 | /* | |
88 | TODO : |
|
88 | TODO : | |
89 | intergrate a per BLKDEV or per partition buffer. |
|
89 | intergrate a per BLKDEV or per partition buffer. | |
90 | */ |
|
90 | */ | |
91 | typedef struct FAT32fs |
|
91 | typedef struct FAT32fs | |
92 | { |
|
92 | { | |
93 | uint16_t BPB_BytsPerSec; |
|
93 | uint16_t BPB_BytsPerSec; | |
94 | uint16_t BPB_RsvdSecCnt; |
|
94 | uint16_t BPB_RsvdSecCnt; | |
95 | uint32_t BPB_FATSz32; |
|
95 | uint32_t BPB_FATSz32; | |
96 | uint32_t BPB_RootClus; |
|
96 | uint32_t BPB_RootClus; | |
97 | uint32_t fat_begin_lba; |
|
97 | uint32_t fat_begin_lba; | |
98 | uint32_t cluster_begin_lba; |
|
98 | uint32_t cluster_begin_lba; | |
99 | uint8_t BPB_SecPerClus; |
|
99 | uint8_t BPB_SecPerClus; | |
100 | uint8_t BPB_NumFATs; |
|
100 | uint8_t BPB_NumFATs; | |
101 | char valide; |
|
101 | char valide; | |
102 |
|
|
102 | dikpartition* part; | |
103 | }FAT32fs; |
|
103 | }FAT32fs; | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | #define castUI64(val) ((uint64_t)(val)) |
|
106 | #define castUI64(val) ((uint64_t)(val)) | |
107 | #define castUI32(val) ((uint32_t)(val)) |
|
107 | #define castUI32(val) ((uint32_t)(val)) | |
108 | #define castUI16(val) ((uint16_t)(val)) |
|
108 | #define castUI16(val) ((uint16_t)(val)) | |
109 | #define castUI8(val) ((uint8_t)(val)) |
|
109 | #define castUI8(val) ((uint8_t)(val)) | |
110 |
|
110 | |||
111 | #define castI64(val) ((int64_t)(val)) |
|
111 | #define castI64(val) ((int64_t)(val)) | |
112 | #define castI32(val) ((int32_t)(val)) |
|
112 | #define castI32(val) ((int32_t)(val)) | |
113 | #define castI16(val) ((int16_t)(val)) |
|
113 | #define castI16(val) ((int16_t)(val)) | |
114 | #define castI8(val) ((int8_t)(val)) |
|
114 | #define castI8(val) ((int8_t)(val)) | |
115 |
|
115 | |||
116 | /* |
|
116 | /* | |
117 | TODO : |
|
117 | TODO : | |
118 | Should add global function for casting with endianness care. |
|
118 | Should add global function for casting with endianness care. | |
119 | have a look at REV, REV16, REVSH, and RBIT ARMV7m asm |
|
119 | have a look at REV, REV16, REVSH, and RBIT ARMV7m asm | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
122 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
123 | #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) |
|
123 | #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) | |
124 | #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) |
|
124 | #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) | |
125 | #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) |
|
125 | #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) | |
126 | #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) |
|
126 | #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) | |
127 | #else |
|
127 | #else | |
128 | #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) |
|
128 | #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24)))) | |
129 | #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) |
|
129 | #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8)))) | |
130 | #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) |
|
130 | #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )) | |
131 | #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) |
|
131 | #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 )) | |
132 | #endif |
|
132 | #endif | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | /* Get the first sector lba of given cluster number*/ |
|
135 | /* Get the first sector lba of given cluster number*/ | |
136 | #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus) |
|
136 | #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus) | |
137 |
|
137 | |||
138 | //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba) |
|
138 | //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba) | |
139 | #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba) |
|
139 | #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba) | |
140 | #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4) |
|
140 | #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4) | |
141 |
|
141 | |||
142 | /*Get cluster index in FAT Table from sector address*/ |
|
142 | /*Get cluster index in FAT Table from sector address*/ | |
143 | #define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1))) |
|
143 | #define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1))) | |
144 | #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2)) |
|
144 | #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2)) | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | #ifdef FAT32_PRIVATE |
|
147 | #ifdef FAT32_PRIVATE | |
148 | #define fat32sectorreadout(fs,fatsec) \ |
|
148 | #define fat32sectorreadout(fs,fatsec) \ | |
149 | if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \ |
|
149 | if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \ | |
150 | {\ |
|
150 | {\ | |
151 | if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \ |
|
151 | if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \ | |
152 | {\ |
|
152 | {\ | |
153 | return DIRENT_ReadErr;\ |
|
153 | return DIRENT_ReadErr;\ | |
154 | }\ |
|
154 | }\ | |
155 | }\ |
|
155 | }\ | |
156 | lastSecAddrs=(fatsec);\ |
|
156 | lastSecAddrs=(fatsec);\ | |
157 | lastFATFS=(fs); |
|
157 | lastFATFS=(fs); | |
158 | #endif |
|
158 | #endif | |
159 |
|
159 | |||
160 | extern int fat32open(FAT32fs* fs,dikpartition* part); |
|
160 | extern int fat32open(FAT32fs* fs,dikpartition* part); | |
161 | extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent); |
|
161 | extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent); | |
162 | extern int fat32getVolName(FAT32fs* fs,char* Name); |
|
162 | extern int fat32getVolName(FAT32fs* fs,char* Name); | |
163 | extern int fat32getrootfirstent(ucdirent* entry); |
|
163 | extern int fat32getrootfirstent(ucdirent* entry); | |
164 | extern int fat32nextdirent(ucdirent* entry); |
|
164 | extern int fat32nextdirent(ucdirent* entry); | |
165 | extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba); |
|
165 | extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba); | |
166 | extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba); |
|
166 | extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba); | |
167 | extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba); |
|
167 | extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba); | |
168 | extern uint32_t fat32getdirentlba(ucdirent* entry); |
|
168 | extern uint32_t fat32getdirentlba(ucdirent* entry); | |
169 | extern int fat32getdirentname(ucdirent* entry,char* nameBuffer); |
|
169 | extern int fat32getdirentname(ucdirent* entry,char* nameBuffer); | |
170 |
|
170 | |||
171 | #endif |
|
171 | #endif | |
172 |
|
172 | |||
173 |
|
173 | |||
174 |
|
174 | |||
175 |
|
175 | |||
176 |
|
176 | |||
177 |
|
177 | |||
178 |
|
178 | |||
179 |
|
179 | |||
180 |
|
180 | |||
181 |
|
181 | |||
182 |
|
182 | |||
183 |
|
183 | |||
184 |
|
184 | |||
185 |
|
185 | |||
186 |
|
186 | |||
187 |
|
187 | |||
188 |
|
188 | |||
189 |
|
189 | |||
190 |
|
190 | |||
191 |
|
191 | |||
192 |
|
192 | |||
193 |
|
193 | |||
194 |
|
194 | |||
195 |
|
195 | |||
196 |
|
@@ -1,115 +1,116 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <sdcard.h> |
|
2 | #include <sdcard.h> | |
3 | #include <sdcard-spi.h> |
|
3 | #include <sdcard-spi.h> | |
4 |
|
4 | |||
5 | FILE* sdcardimg; |
|
5 | FILE* sdcardimg=NULL; | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy)) |
|
8 | void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy)) | |
9 | { |
|
9 | { | |
10 |
|
10 | |||
11 | } |
|
11 | } | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | int sdcardselect (blkdevice* _this) |
|
14 | int sdcardselect (blkdevice* _this) | |
15 | { |
|
15 | { | |
16 | return 1; |
|
16 | return 1; | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | void sdcarddeselect (blkdevice* _this) |
|
20 | void sdcarddeselect (blkdevice* _this) | |
21 | { |
|
21 | { | |
22 |
|
22 | |||
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | int sdcardwait_ready (sdcardDev* sdcard) |
|
25 | int sdcardwait_ready (sdcardDev* sdcard) | |
26 | { |
|
26 | { | |
27 | return 1; |
|
27 | return 1; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | void sdcardpower (blkdevice* _this) |
|
30 | void sdcardpower (blkdevice* _this) | |
31 | { |
|
31 | { | |
32 |
|
32 | |||
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | char sdcarddetect (blkdevice* _this) |
|
35 | char sdcarddetect (blkdevice* _this) | |
36 | { |
|
36 | { | |
37 | return 1; |
|
37 | return 1; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | char sdcardwriteprotected (blkdevice* _this) |
|
40 | char sdcardwriteprotected (blkdevice* _this) | |
41 | { |
|
41 | { | |
42 | return 0; |
|
42 | return 0; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 |
|
45 | |||
46 |
|
46 | |||
47 | int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token) |
|
47 | int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token) | |
48 | { |
|
48 | { | |
49 | return 1; |
|
49 | return 1; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr) |
|
52 | int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr) | |
53 | { |
|
53 | { | |
54 | return 1; |
|
54 | return 1; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg) |
|
57 | char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg) | |
58 | { |
|
58 | { | |
59 | return 1; |
|
59 | return 1; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | DSTATUS sdcarddisk_status (blkdevice* _this) |
|
62 | DSTATUS sdcarddisk_status (blkdevice* _this) | |
63 | {} |
|
63 | {} | |
64 |
|
64 | |||
65 | DSTATUS sdcarddisk_initialize (blkdevice* _this) |
|
65 | DSTATUS sdcarddisk_initialize (blkdevice* _this) | |
66 | {} |
|
66 | {} | |
67 |
|
67 | |||
68 | DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) |
|
68 | DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count) | |
69 | { |
|
69 | { | |
|
70 | if(sdcardimg==NULL)return RES_ERROR; | |||
70 | int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); |
|
71 | int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); | |
71 | if(count*512== fread(buff,1,count*512,sdcardimg)) |
|
72 | if(count*512== fread(buff,1,count*512,sdcardimg)) | |
72 | return RES_OK; |
|
73 | return RES_OK; | |
73 | return RES_ERROR; |
|
74 | return RES_ERROR; | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) |
|
77 | DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count) | |
77 | { |
|
78 | { | |
|
79 | if(sdcardimg==NULL)return RES_ERROR; | |||
78 | fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); |
|
80 | fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET); | |
79 | fwrite(buff,1,count*512,sdcardimg); |
|
81 | fwrite(buff,1,count*512,sdcardimg); | |
80 | return RES_OK; |
|
82 | return RES_OK; | |
81 | } |
|
83 | } | |
82 |
|
84 | |||
83 | DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff) |
|
85 | DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff) | |
84 | {} |
|
86 | {} | |
85 |
|
87 | |||
86 |
|
88 | |||
87 | void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) |
|
89 | void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) | |
88 | { |
|
90 | { | |
89 |
sdcardimg=fopen("sdc |
|
91 | sdcardimg=fopen("/dev/sdc","rb"); | |
90 | // sdcardimg=fopen("usbkey.bin","rb"); |
|
92 | // sdcardimg=fopen("usbkey.bin","rb"); | |
91 | if(sdcardimg!=NULL)printf("ok sdcard openned\n"); |
|
93 | if(sdcardimg!=NULL)printf("ok sdcard openned\n"); | |
92 | else printf("Nok sdcard not openned\n"); |
|
94 | else printf("Nok sdcard not openned\n"); | |
93 | dev->phy=NULL; |
|
95 | dev->phy=NULL; | |
94 | dev->select= (blkdevselect_t)select; |
|
96 | dev->select= (blkdevselect_t)select; | |
95 | dev->power = (blkdevpower_t)power; |
|
97 | dev->power = (blkdevpower_t)power; | |
96 | dev->detect = (blkdevdetect_t)detect; |
|
98 | dev->detect = (blkdevdetect_t)detect; | |
97 | dev->writeprotected = (blkdevwriteprotected_t)writeprotected; |
|
99 | dev->writeprotected = (blkdevwriteprotected_t)writeprotected; | |
98 | dev->write = sdcarddisk_write; |
|
100 | dev->write = sdcarddisk_write; | |
99 | dev->read = sdcarddisk_read; |
|
101 | dev->read = sdcarddisk_read; | |
100 | dev->ioctl = sdcarddisk_ioctl; |
|
102 | dev->ioctl = sdcarddisk_ioctl; | |
101 | dev->initialize = sdcarddisk_initialize; |
|
103 | dev->initialize = sdcarddisk_initialize; | |
102 | dev->status = sdcarddisk_status; |
|
104 | dev->status = sdcarddisk_status; | |
103 | printf("sdcard opened\n"); |
|
|||
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 |
|
107 | |||
107 |
|
108 | |||
108 |
|
109 | |||
109 |
|
110 | |||
110 |
|
111 | |||
111 |
|
112 | |||
112 |
|
113 | |||
113 |
|
114 | |||
114 |
|
115 | |||
115 |
|
116 |
@@ -1,316 +1,333 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2013, Alexis Jeandet |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 |
|
22 | |||
23 | #include <SDL.h> |
|
23 | #include <SDL.h> | |
24 | #include <malloc.h> |
|
24 | #include <malloc.h> | |
25 | #include "SDLCD.h" |
|
25 | #include "SDLCD.h" | |
26 |
|
26 | |||
27 | SDL_Surface *screen; |
|
27 | SDL_Surface *screen; | |
28 | SDL_Overlay *bmp; |
|
28 | SDL_Overlay *bmp; | |
29 |
|
29 | |||
30 | int SDLCD_Xpos=0; |
|
30 | int SDLCD_Xpos=0; | |
31 | int SDLCD_Ypos=0; |
|
31 | int SDLCD_Ypos=0; | |
32 | int SDLCD_XWinStrt=0; |
|
32 | int SDLCD_XWinStrt=0; | |
33 | int SDLCD_YWinStrt=0; |
|
33 | int SDLCD_YWinStrt=0; | |
34 | int SDLCD_XWinEnd=0; |
|
34 | int SDLCD_XWinEnd=0; | |
35 | int SDLCD_YWinEnd=0; |
|
35 | int SDLCD_YWinEnd=0; | |
36 |
|
36 | |||
37 | void* SDLCD_buffer; |
|
37 | void* SDLCD_buffer; | |
38 | int SDLCD_bpp; |
|
38 | int SDLCD_bpp; | |
39 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); |
|
39 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); | |
40 |
|
40 | |||
|
41 | static Uint32 sdl_refresh_timer(Uint32 interval, void *opaque) { | |||
|
42 | ||||
|
43 | if ( SDL_MUSTLOCK(screen) ) { | |||
|
44 | if ( SDL_LockSurface(screen) < 0 ) { | |||
|
45 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); | |||
|
46 | return interval; | |||
|
47 | } | |||
|
48 | } | |||
|
49 | //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); | |||
|
50 | SDL_Flip(screen); | |||
|
51 | if ( SDL_MUSTLOCK(screen) ) { | |||
|
52 | SDL_UnlockSurface(screen); | |||
|
53 | } | |||
|
54 | return interval; /* 0 means stop timer */ | |||
|
55 | } | |||
|
56 | ||||
41 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) |
|
57 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) | |
42 | { |
|
58 | { | |
43 | int i=0; |
|
59 | int i=0; | |
44 | if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { |
|
60 | if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { | |
45 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); |
|
61 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); | |
46 | exit(1); |
|
62 | exit(1); | |
47 | } |
|
63 | } | |
48 |
screen = SDL_SetVideoMode(resx, resy, bpp, |
|
64 | screen = SDL_SetVideoMode(resx, resy, bpp, SDL_DOUBLEBUF); | |
49 | if(!screen) { |
|
65 | if(!screen) { | |
50 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); |
|
66 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); | |
51 | exit(1); |
|
67 | exit(1); | |
52 | } |
|
68 | } | |
53 | if ( SDL_MUSTLOCK(screen) ) { |
|
69 | if ( SDL_MUSTLOCK(screen) ) { | |
54 | if ( SDL_LockSurface(screen) < 0 ) { |
|
70 | if ( SDL_LockSurface(screen) < 0 ) { | |
55 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
71 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); | |
56 | return; |
|
72 | return; | |
57 | } |
|
73 | } | |
58 | } |
|
74 | } | |
|
75 | SDL_UpdateRect(screen, 0, 0, resx, resy); | |||
59 | if ( SDL_MUSTLOCK(screen) ) { |
|
76 | if ( SDL_MUSTLOCK(screen) ) { | |
60 | SDL_UnlockSurface(screen); |
|
77 | SDL_UnlockSurface(screen); | |
61 | } |
|
78 | } | |
62 | SDL_UpdateRect(screen, 0, 0, resx, resy); |
|
|||
63 | SDLCD_buffer = malloc(resx*resy*bpp/8); |
|
79 | SDLCD_buffer = malloc(resx*resy*bpp/8); | |
64 | SDLCD_bpp = bpp; |
|
80 | SDLCD_bpp = bpp; | |
65 | for(i=0;i<(resx*resy);i++) |
|
81 | for(i=0;i<(resx*resy);i++) | |
66 | { |
|
82 | { | |
67 | SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); |
|
83 | SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); | |
68 | } |
|
84 | } | |
|
85 | SDL_AddTimer(10, sdl_refresh_timer, NULL); | |||
69 | } |
|
86 | } | |
70 |
|
87 | |||
71 |
|
88 | |||
72 |
|
89 | |||
73 | int SDLCD_init() |
|
90 | int SDLCD_init() | |
74 | { |
|
91 | { | |
75 |
|
92 | |||
76 | } |
|
93 | } | |
77 |
|
94 | |||
78 | void SDLCD_writereg(uint32_t reg,uint32_t data) |
|
95 | void SDLCD_writereg(uint32_t reg,uint32_t data) | |
79 | { |
|
96 | { | |
80 | switch (reg) { |
|
97 | switch (reg) { | |
81 | case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET: |
|
98 | case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET: | |
82 | if((data>=screen->w) || (data<0)) |
|
99 | if((data>=screen->w) || (data<0)) | |
83 | printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data); |
|
100 | printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data); | |
84 | SDLCD_Xpos = data; |
|
101 | SDLCD_Xpos = data; | |
85 | break; |
|
102 | break; | |
86 | case ILI9328_REGISTER_VERTICALGRAMADDRESSSET: |
|
103 | case ILI9328_REGISTER_VERTICALGRAMADDRESSSET: | |
87 | if((data>=screen->h) || (data<0)) |
|
104 | if((data>=screen->h) || (data<0)) | |
88 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data); |
|
105 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data); | |
89 | SDLCD_Ypos = data; |
|
106 | SDLCD_Ypos = data; | |
90 | break; |
|
107 | break; | |
91 | case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION: |
|
108 | case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION: | |
92 | if((data>=screen->w) || (data<0)) |
|
109 | if((data>=screen->w) || (data<0)) | |
93 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data); |
|
110 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data); | |
94 | SDLCD_XWinStrt = data; |
|
111 | SDLCD_XWinStrt = data; | |
95 | break; |
|
112 | break; | |
96 | case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION: |
|
113 | case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION: | |
97 | if((data>=screen->w) || (data<0)) |
|
114 | if((data>=screen->w) || (data<0)) | |
98 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data); |
|
115 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data); | |
99 | SDLCD_XWinEnd = data; |
|
116 | SDLCD_XWinEnd = data; | |
100 | break; |
|
117 | break; | |
101 | case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION: |
|
118 | case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION: | |
102 | if((data>=screen->h) || (data<0)) |
|
119 | if((data>=screen->h) || (data<0)) | |
103 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data); |
|
120 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data); | |
104 | SDLCD_YWinStrt = data; |
|
121 | SDLCD_YWinStrt = data; | |
105 | break; |
|
122 | break; | |
106 | case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION: |
|
123 | case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION: | |
107 | if((data>=screen->h) || (data<0)) |
|
124 | if((data>=screen->h) || (data<0)) | |
108 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data); |
|
125 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data); | |
109 | SDLCD_YWinEnd = data; |
|
126 | SDLCD_YWinEnd = data; | |
110 | break; |
|
127 | break; | |
111 | default: |
|
128 | default: | |
112 | break; |
|
129 | break; | |
113 | } |
|
130 | } | |
114 | } |
|
131 | } | |
115 |
|
132 | |||
116 | uint32_t SDLCD_readreg(uint32_t reg) |
|
133 | uint32_t SDLCD_readreg(uint32_t reg) | |
117 | { |
|
134 | { | |
118 | return 0; |
|
135 | return 0; | |
119 | } |
|
136 | } | |
120 |
|
137 | |||
121 |
|
138 | |||
122 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
139 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) | |
123 | { |
|
140 | { | |
124 | int bpp = surface->format->BytesPerPixel; |
|
141 | int bpp = surface->format->BytesPerPixel; | |
125 | /* Here p is the address to the pixel we want to set */ |
|
142 | /* Here p is the address to the pixel we want to set */ | |
126 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
143 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
127 | switch(bpp) { |
|
144 | switch(bpp) { | |
128 | case 1: |
|
145 | case 1: | |
129 | *p = pixel; |
|
146 | *p = pixel; | |
130 | break; |
|
147 | break; | |
131 | case 2: |
|
148 | case 2: | |
132 | *(Uint16 *)p = pixel; |
|
149 | *(Uint16 *)p = pixel; | |
133 | break; |
|
150 | break; | |
134 | case 3: |
|
151 | case 3: | |
135 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
152 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { | |
136 | p[0] = (pixel >> 16) & 0xff; |
|
153 | p[0] = (pixel >> 16) & 0xff; | |
137 | p[1] = (pixel >> 8) & 0xff; |
|
154 | p[1] = (pixel >> 8) & 0xff; | |
138 | p[2] = pixel & 0xff; |
|
155 | p[2] = pixel & 0xff; | |
139 | } else { |
|
156 | } else { | |
140 | p[0] = pixel & 0xff; |
|
157 | p[0] = pixel & 0xff; | |
141 | p[1] = (pixel >> 8) & 0xff; |
|
158 | p[1] = (pixel >> 8) & 0xff; | |
142 | p[2] = (pixel >> 16) & 0xff; |
|
159 | p[2] = (pixel >> 16) & 0xff; | |
143 | } |
|
160 | } | |
144 | break; |
|
161 | break; | |
145 | case 4: |
|
162 | case 4: | |
146 | *(Uint32 *)p = pixel; |
|
163 | *(Uint32 *)p = pixel; | |
147 | break; |
|
164 | break; | |
148 | } |
|
165 | } | |
149 | } |
|
166 | } | |
150 |
|
167 | |||
151 | void SDLCD_putpixel_16bpp(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
168 | void SDLCD_putpixel_16bpp(SDL_Surface *surface, int x, int y, Uint32 pixel) | |
152 | { |
|
169 | { | |
153 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
170 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; | |
154 | *(Uint16 *)p = pixel; |
|
171 | *(Uint16 *)p = pixel; | |
155 | } |
|
172 | } | |
156 |
|
173 | |||
157 | Uint32 SDLCD_getpixel_16bpp(SDL_Surface *surface, int x, int y) |
|
174 | Uint32 SDLCD_getpixel_16bpp(SDL_Surface *surface, int x, int y) | |
158 | { |
|
175 | { | |
159 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
176 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; | |
160 | return *(Uint16 *)p; |
|
177 | return *(Uint16 *)p; | |
161 | } |
|
178 | } | |
162 |
|
179 | |||
163 | Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y) |
|
180 | Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y) | |
164 | { |
|
181 | { | |
165 | int bpp = surface->format->BytesPerPixel; |
|
182 | int bpp = surface->format->BytesPerPixel; | |
166 | /* Here p is the address to the pixel we want to retrieve */ |
|
183 | /* Here p is the address to the pixel we want to retrieve */ | |
167 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
184 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | |
168 | switch(bpp) { |
|
185 | switch(bpp) { | |
169 | case 1: |
|
186 | case 1: | |
170 | return *p; |
|
187 | return *p; | |
171 | case 2: |
|
188 | case 2: | |
172 | return *(Uint16 *)p; |
|
189 | return *(Uint16 *)p; | |
173 | case 3: |
|
190 | case 3: | |
174 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
191 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
175 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
192 | return p[0] << 16 | p[1] << 8 | p[2]; | |
176 | else |
|
193 | else | |
177 | return p[0] | p[1] << 8 | p[2] << 16; |
|
194 | return p[0] | p[1] << 8 | p[2] << 16; | |
178 | case 4: |
|
195 | case 4: | |
179 | return *(Uint32 *)p; |
|
196 | return *(Uint32 *)p; | |
180 | default: |
|
197 | default: | |
181 | return 0; |
|
198 | return 0; | |
182 | } |
|
199 | } | |
183 | /* shouldnβt happen, but avoids warnings */ |
|
200 | /* shouldnβt happen, but avoids warnings */ | |
184 | } |
|
201 | } | |
185 |
|
202 | |||
186 | void SDLCD_writeGRAM(void* buffer,uint32_t count) |
|
203 | void SDLCD_writeGRAM(void* buffer,uint32_t count) | |
187 | { |
|
204 | { | |
188 | int i=0; |
|
205 | int i=0; | |
189 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
206 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; | |
190 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
207 | u_int16_t* inptr=(u_int16_t*)buffer; | |
191 | if ( SDL_MUSTLOCK(screen) ) { |
|
208 | if ( SDL_MUSTLOCK(screen) ) { | |
192 | if ( SDL_LockSurface(screen) < 0 ) { |
|
209 | if ( SDL_LockSurface(screen) < 0 ) { | |
193 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
210 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); | |
194 | return; |
|
211 | return; | |
195 | } |
|
212 | } | |
196 | } |
|
213 | } | |
197 | for(i=0;i<count;i++) |
|
214 | for(i=0;i<count;i++) | |
198 | { |
|
215 | { | |
199 | SDLCD_putpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]); |
|
216 | SDLCD_putpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]); | |
200 | SDLCD_Xpos+=1; |
|
217 | SDLCD_Xpos+=1; | |
201 | ptr[i]=inptr[i]; |
|
218 | ptr[i]=inptr[i]; | |
202 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
219 | if(SDLCD_Xpos>=SDLCD_XWinEnd) | |
203 | { |
|
220 | { | |
204 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
221 | SDLCD_Xpos=SDLCD_XWinStrt; | |
205 | SDLCD_Ypos+=1; |
|
222 | SDLCD_Ypos+=1; | |
206 | } |
|
223 | } | |
207 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
224 | if(SDLCD_Ypos>=SDLCD_YWinEnd) | |
208 | { |
|
225 | { | |
209 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
226 | SDLCD_Ypos=SDLCD_YWinStrt; | |
210 | } |
|
227 | } | |
211 | } |
|
228 | } | |
212 | if ( SDL_MUSTLOCK(screen) ) { |
|
229 | if ( SDL_MUSTLOCK(screen) ) { | |
213 | SDL_UnlockSurface(screen); |
|
230 | SDL_UnlockSurface(screen); | |
214 | } |
|
231 | } | |
215 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
232 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); | |
216 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
233 | //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); | |
217 | } |
|
234 | } | |
218 |
|
235 | |||
219 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) |
|
236 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) | |
220 | { |
|
237 | { | |
221 | int i=0; |
|
238 | int i=0; | |
222 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
239 | u_int16_t* inptr=(u_int16_t*)buffer; | |
223 | if ( SDL_MUSTLOCK(screen) ) { |
|
240 | if ( SDL_MUSTLOCK(screen) ) { | |
224 | if ( SDL_LockSurface(screen) < 0 ) { |
|
241 | if ( SDL_LockSurface(screen) < 0 ) { | |
225 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
242 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); | |
226 | return; |
|
243 | return; | |
227 | } |
|
244 | } | |
228 | } |
|
245 | } | |
229 | for(i=0;i<count;i++) |
|
246 | for(i=0;i<count;i++) | |
230 | { |
|
247 | { | |
231 | *(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos)=inptr[i]; |
|
248 | *(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos)=inptr[i]; | |
232 | SDLCD_Xpos+=1; |
|
249 | SDLCD_Xpos+=1; | |
233 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
250 | if(SDLCD_Xpos>=SDLCD_XWinEnd) | |
234 | { |
|
251 | { | |
235 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
252 | SDLCD_Xpos=SDLCD_XWinStrt; | |
236 | SDLCD_Ypos+=1; |
|
253 | SDLCD_Ypos+=1; | |
237 | } |
|
254 | } | |
238 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
255 | if(SDLCD_Ypos>=SDLCD_YWinEnd) | |
239 | { |
|
256 | { | |
240 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
257 | SDLCD_Ypos=SDLCD_YWinStrt; | |
241 | } |
|
258 | } | |
242 | } |
|
259 | } | |
243 | if ( SDL_MUSTLOCK(screen) ) { |
|
260 | if ( SDL_MUSTLOCK(screen) ) { | |
244 | SDL_UnlockSurface(screen); |
|
261 | SDL_UnlockSurface(screen); | |
245 | } |
|
262 | } | |
246 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
263 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); | |
247 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
264 | //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); | |
248 | } |
|
265 | } | |
249 |
|
266 | |||
250 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) |
|
267 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) | |
251 | { |
|
268 | { | |
252 | int i=0; |
|
269 | int i=0; | |
253 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
270 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; | |
254 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
271 | u_int16_t* inptr=(u_int16_t*)buffer; | |
255 | for(i=0;i<count;i++) |
|
272 | for(i=0;i<count;i++) | |
256 | { |
|
273 | { | |
257 | inptr[i]=*(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos); |
|
274 | inptr[i]=*(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos); | |
258 | SDLCD_Xpos+=1; |
|
275 | SDLCD_Xpos+=1; | |
259 | ptr[i]=inptr[i]; |
|
276 | ptr[i]=inptr[i]; | |
260 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
277 | if(SDLCD_Xpos>=SDLCD_XWinEnd) | |
261 | { |
|
278 | { | |
262 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
279 | SDLCD_Xpos=SDLCD_XWinStrt; | |
263 | SDLCD_Ypos+=1; |
|
280 | SDLCD_Ypos+=1; | |
264 | } |
|
281 | } | |
265 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
282 | if(SDLCD_Ypos>=SDLCD_YWinEnd) | |
266 | { |
|
283 | { | |
267 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
284 | SDLCD_Ypos=SDLCD_YWinStrt; | |
268 | } |
|
285 | } | |
269 | } |
|
286 | } | |
270 |
|
287 | |||
271 | } |
|
288 | } | |
272 |
|
289 | |||
273 | void SDLCD_readGRAM(void* buffer,uint32_t count) |
|
290 | void SDLCD_readGRAM(void* buffer,uint32_t count) | |
274 | { |
|
291 | { | |
275 | int i=0; |
|
292 | int i=0; | |
276 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
293 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; | |
277 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
294 | u_int16_t* inptr=(u_int16_t*)buffer; | |
278 | for(i=0;i<count;i++) |
|
295 | for(i=0;i<count;i++) | |
279 | { |
|
296 | { | |
280 | inptr[i]=SDLCD_getpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos); |
|
297 | inptr[i]=SDLCD_getpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos); | |
281 | SDLCD_Xpos+=1; |
|
298 | SDLCD_Xpos+=1; | |
282 | ptr[i]=inptr[i]; |
|
299 | ptr[i]=inptr[i]; | |
283 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
300 | if(SDLCD_Xpos>=SDLCD_XWinEnd) | |
284 | { |
|
301 | { | |
285 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
302 | SDLCD_Xpos=SDLCD_XWinStrt; | |
286 | SDLCD_Ypos+=1; |
|
303 | SDLCD_Ypos+=1; | |
287 | } |
|
304 | } | |
288 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
305 | if(SDLCD_Ypos>=SDLCD_YWinEnd) | |
289 | { |
|
306 | { | |
290 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
307 | SDLCD_Ypos=SDLCD_YWinStrt; | |
291 | } |
|
308 | } | |
292 | } |
|
309 | } | |
293 |
|
310 | |||
294 | } |
|
311 | } | |
295 |
|
312 | |||
296 |
|
313 | |||
297 |
|
314 | |||
298 |
|
315 | |||
299 |
|
316 | |||
300 |
|
317 | |||
301 |
|
318 | |||
302 |
|
319 | |||
303 |
|
320 | |||
304 |
|
321 | |||
305 |
|
322 | |||
306 |
|
323 | |||
307 |
|
324 | |||
308 |
|
325 | |||
309 |
|
326 | |||
310 |
|
327 | |||
311 |
|
328 | |||
312 |
|
329 | |||
313 |
|
330 | |||
314 |
|
331 | |||
315 |
|
332 | |||
316 |
|
333 |
General Comments 0
You need to be logged in to leave comments.
Login now