[sky9x] Issue 142 fixed
[sky9x] Tada was cut [sky9x] Issue 99 fixed [sky9x / gruvin9x] Menu popup has now a scrollbar on the right [sky9x] WDT was not working at all
This commit is contained in:
+2
-46
@@ -183,50 +183,6 @@ inline void setup_switches()
|
|||||||
#define sam_boot()
|
#define sam_boot()
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures a UART peripheral with the specified parameters.
|
|
||||||
*
|
|
||||||
* baudrate Baudrate at which the UART should operate (in Hz).
|
|
||||||
* masterClock Frequency of the system master clock (in Hz).
|
|
||||||
* uses PA9 and PA10, RXD2 and TXD2
|
|
||||||
*/
|
|
||||||
inline void UART_Configure( uint32_t baudrate, uint32_t masterClock)
|
|
||||||
{
|
|
||||||
// const Pin pPins[] = CONSOLE_PINS;
|
|
||||||
register Uart *pUart = CONSOLE_USART;
|
|
||||||
|
|
||||||
/* Configure PIO */
|
|
||||||
configure_pins( (PIO_PA9 | PIO_PA10), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
|
|
||||||
|
|
||||||
/* Configure PMC */
|
|
||||||
PMC->PMC_PCER0 = 1 << CONSOLE_ID;
|
|
||||||
|
|
||||||
/* Reset and disable receiver & transmitter */
|
|
||||||
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
|
||||||
| UART_CR_RXDIS | UART_CR_TXDIS;
|
|
||||||
|
|
||||||
/* Configure mode */
|
|
||||||
pUart->UART_MR = 0x800 ; // NORMAL, No Parity
|
|
||||||
|
|
||||||
/* Configure baudrate */
|
|
||||||
/* Asynchronous, no oversampling */
|
|
||||||
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
|
||||||
|
|
||||||
/* Disable PDC channel */
|
|
||||||
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
|
||||||
|
|
||||||
/* Enable receiver and transmitter */
|
|
||||||
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
|
||||||
pUart->UART_IER = UART_IER_RXRDY ;
|
|
||||||
NVIC_EnableIRQ(UART0_IRQn) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UART_Stop()
|
|
||||||
{
|
|
||||||
CONSOLE_USART->UART_IDR = UART_IDR_RXRDY ;
|
|
||||||
NVIC_DisableIRQ(UART0_IRQn) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void UART3_Configure( uint32_t baudrate, uint32_t masterClock)
|
inline void UART3_Configure( uint32_t baudrate, uint32_t masterClock)
|
||||||
{
|
{
|
||||||
// const Pin pPins[] = CONSOLE_PINS;
|
// const Pin pPins[] = CONSOLE_PINS;
|
||||||
@@ -777,7 +733,7 @@ void board_init()
|
|||||||
PMC->PMC_SCER |= 0x0400 ; // PCK2 enabled
|
PMC->PMC_SCER |= 0x0400 ; // PCK2 enabled
|
||||||
PMC->PMC_PCK[2] = 2 ; // PCK2 is PLLA
|
PMC->PMC_PCK[2] = 2 ; // PCK2 is PLLA
|
||||||
|
|
||||||
UART_Configure( 9600, Master_frequency ) ;
|
DEBUG_UART_Configure( 9600, Master_frequency ) ;
|
||||||
UART2_Configure( 9600, Master_frequency ) ; // Testing
|
UART2_Configure( 9600, Master_frequency ) ; // Testing
|
||||||
UART3_Configure( 9600, Master_frequency ) ; // TODO not needed, done after ...
|
UART3_Configure( 9600, Master_frequency ) ; // TODO not needed, done after ...
|
||||||
|
|
||||||
@@ -1203,7 +1159,7 @@ void usb_mode()
|
|||||||
// NVIC_DisableIRQ(PWM_IRQn) ;
|
// NVIC_DisableIRQ(PWM_IRQn) ;
|
||||||
disable_ssc() ;
|
disable_ssc() ;
|
||||||
|
|
||||||
UART_Stop();
|
DEBUG_UART_Stop();
|
||||||
UART3_Stop();
|
UART3_Stop();
|
||||||
|
|
||||||
sam_boot() ;
|
sam_boot() ;
|
||||||
|
|||||||
+34
-34
@@ -394,8 +394,40 @@ void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att)
|
|||||||
lcd_hlineStip(x, y, w, 0xff, att);
|
lcd_hlineStip(x, y, w, 0xff, att);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if defined(PCBSTD)
|
||||||
// allows the att parameter... perhaps will be needed later!
|
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat)
|
||||||
|
{
|
||||||
|
if (x >= DISPLAY_W) return;
|
||||||
|
if (h<0) { y+=h; h=-h; }
|
||||||
|
if (y<0) { h+=y; y=0; }
|
||||||
|
if (y+h > DISPLAY_H) { h = DISPLAY_H - y; }
|
||||||
|
|
||||||
|
if (pat==DOTTED && !(y%2))
|
||||||
|
pat = ~pat;
|
||||||
|
|
||||||
|
uint8_t *p = &displayBuf[ y / 8 * DISPLAY_W + x ];
|
||||||
|
y = y % 8;
|
||||||
|
if (y) {
|
||||||
|
ASSERT_IN_DISPLAY(p);
|
||||||
|
*p ^= ~(BITMASK(y)-1) & pat;
|
||||||
|
p += DISPLAY_W;
|
||||||
|
h -= 8-y;
|
||||||
|
}
|
||||||
|
while (h>0) {
|
||||||
|
ASSERT_IN_DISPLAY(p);
|
||||||
|
*p ^= pat;
|
||||||
|
p += DISPLAY_W;
|
||||||
|
h -= 8;
|
||||||
|
}
|
||||||
|
if (h < 0) h += 8;
|
||||||
|
if (h) {
|
||||||
|
p -= DISPLAY_W;
|
||||||
|
ASSERT_IN_DISPLAY(p);
|
||||||
|
*p ^= ~(BITMASK(h)-1) & pat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// allows the att parameter...
|
||||||
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att)
|
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att)
|
||||||
{
|
{
|
||||||
if (x >= DISPLAY_W) return;
|
if (x >= DISPLAY_W) return;
|
||||||
@@ -428,38 +460,6 @@ void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att)
|
|||||||
lcd_mask(p, (BITMASK(h)-1) & pat, att);
|
lcd_mask(p, (BITMASK(h)-1) & pat, att);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat)
|
|
||||||
{
|
|
||||||
if (x >= DISPLAY_W) return;
|
|
||||||
if (h<0) { y+=h; h=-h; }
|
|
||||||
if (y<0) { h+=y; y=0; }
|
|
||||||
if (y+h > DISPLAY_H) { h = DISPLAY_H - y; }
|
|
||||||
|
|
||||||
if (pat==DOTTED && !(y%2))
|
|
||||||
pat = ~pat;
|
|
||||||
|
|
||||||
uint8_t *p = &displayBuf[ y / 8 * DISPLAY_W + x ];
|
|
||||||
y = y % 8;
|
|
||||||
if (y) {
|
|
||||||
ASSERT_IN_DISPLAY(p);
|
|
||||||
*p ^= ~(BITMASK(y)-1) & pat;
|
|
||||||
p += DISPLAY_W;
|
|
||||||
h -= 8-y;
|
|
||||||
}
|
|
||||||
while (h>0) {
|
|
||||||
ASSERT_IN_DISPLAY(p);
|
|
||||||
*p ^= pat;
|
|
||||||
p += DISPLAY_W;
|
|
||||||
h -= 8;
|
|
||||||
}
|
|
||||||
if (h < 0) h += 8;
|
|
||||||
if (h) {
|
|
||||||
p -= DISPLAY_W;
|
|
||||||
ASSERT_IN_DISPLAY(p);
|
|
||||||
*p ^= ~(BITMASK(h)-1) & pat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void lcd_vline(xcoord_t x, int8_t y, int8_t h)
|
void lcd_vline(xcoord_t x, int8_t y, int8_t h)
|
||||||
|
|||||||
@@ -160,7 +160,11 @@ extern void lcd_plot(xcoord_t x, uint8_t y, uint8_t att=0);
|
|||||||
extern void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att=0);
|
extern void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att=0);
|
||||||
extern void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, uint8_t att=0);
|
extern void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, uint8_t att=0);
|
||||||
extern void lcd_vline(xcoord_t x, int8_t y, int8_t h);
|
extern void lcd_vline(xcoord_t x, int8_t y, int8_t h);
|
||||||
|
#if defined(PCBSTD)
|
||||||
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat);
|
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat);
|
||||||
|
#else
|
||||||
|
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att=0);
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
|
extern void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
|
||||||
extern void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
|
extern void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
|
||||||
|
|||||||
+15
-5
@@ -606,16 +606,15 @@ int8_t switchMenuItem(uint8_t x, uint8_t y, int8_t value, uint8_t attr, uint8_t
|
|||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
const char *s_menu[MENU_MAX_LINES];
|
const char *s_menu[MENU_MAX_LINES];
|
||||||
char s_bss_menu[MENU_MAX_LINES][MENU_LINE_LENGTH]; // TODO in reusable buffer?
|
|
||||||
uint8_t s_menu_item = 0;
|
uint8_t s_menu_item = 0;
|
||||||
uint8_t s_menu_count = 0;
|
uint16_t s_menu_count = 0;
|
||||||
uint8_t s_menu_flags = 0;
|
uint8_t s_menu_flags = 0;
|
||||||
uint8_t s_menu_offset = 0;
|
uint16_t s_menu_offset = 0;
|
||||||
const char * displayMenu(uint8_t event)
|
const char * displayMenu(uint8_t event)
|
||||||
{
|
{
|
||||||
const char * result = NULL;
|
const char * result = NULL;
|
||||||
|
|
||||||
uint8_t display_count = min(s_menu_count, (uint8_t)MENU_MAX_LINES);
|
uint8_t display_count = min(s_menu_count, (uint16_t)MENU_MAX_LINES);
|
||||||
|
|
||||||
lcd_filled_rect(10, 16, DISPLAY_W-20, display_count * (FH+1) + 2, SOLID, WHITE);
|
lcd_filled_rect(10, 16, DISPLAY_W-20, display_count * (FH+1) + 2, SOLID, WHITE);
|
||||||
lcd_rect(10, 16, DISPLAY_W-20, display_count * (FH+1) + 2);
|
lcd_rect(10, 16, DISPLAY_W-20, display_count * (FH+1) + 2);
|
||||||
@@ -625,6 +624,17 @@ const char * displayMenu(uint8_t event)
|
|||||||
if (i == s_menu_item) lcd_filled_rect(11, i*(FH+1) + 2*FH + 1, DISPLAY_W-22, 9);
|
if (i == s_menu_item) lcd_filled_rect(11, i*(FH+1) + 2*FH + 1, DISPLAY_W-22, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s_menu_count > display_count) {
|
||||||
|
// scroll bar
|
||||||
|
lcd_vlineStip(DISPLAY_W-11, 16, MENU_MAX_LINES * (FH+1) + 2, SOLID, WHITE);
|
||||||
|
lcd_vlineStip(DISPLAY_W-11, 16, MENU_MAX_LINES * (FH+1) + 2, DOTTED);
|
||||||
|
uint8_t ofs = (MENU_MAX_LINES * (FH+1) * s_menu_offset) / s_menu_count;
|
||||||
|
uint8_t hgt = (MENU_MAX_LINES * (FH+1) * MENU_MAX_LINES) / s_menu_count;
|
||||||
|
if (hgt + ofs > MENU_MAX_LINES * (FH+1))
|
||||||
|
hgt = MENU_MAX_LINES * (FH+1) - ofs;
|
||||||
|
lcd_vlineStip(DISPLAY_W-11, 16 + ofs, 2 + hgt, SOLID, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
switch(event) {
|
switch(event) {
|
||||||
case EVT_KEY_FIRST(KEY_UP):
|
case EVT_KEY_FIRST(KEY_UP):
|
||||||
if (s_menu_item > 0)
|
if (s_menu_item > 0)
|
||||||
@@ -635,7 +645,7 @@ const char * displayMenu(uint8_t event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVT_KEY_FIRST(KEY_DOWN):
|
case EVT_KEY_FIRST(KEY_DOWN):
|
||||||
if (s_menu_item < display_count - 1)
|
if (s_menu_item < display_count - 1 && s_menu_offset + s_menu_item + 1 < s_menu_count)
|
||||||
s_menu_item++;
|
s_menu_item++;
|
||||||
else if (s_menu_count > s_menu_offset + display_count) {
|
else if (s_menu_count > s_menu_offset + display_count) {
|
||||||
s_menu_offset++;
|
s_menu_offset++;
|
||||||
|
|||||||
+3
-9
@@ -224,17 +224,11 @@ void displayWarning(uint8_t event);
|
|||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
#define MENU_MAX_LINES 4
|
#define MENU_MAX_LINES 4
|
||||||
#include "FatFs/ffconf.h"
|
#define MENU_LINE_LENGTH (LEN_MODEL_NAME+1)
|
||||||
#ifdef _USE_LFN
|
|
||||||
# define MENU_LINE_LENGTH (16+1)
|
|
||||||
#else
|
|
||||||
# define MENU_LINE_LENGTH (8+1)
|
|
||||||
#endif
|
|
||||||
extern const char *s_menu[MENU_MAX_LINES];
|
extern const char *s_menu[MENU_MAX_LINES];
|
||||||
extern char s_bss_menu[MENU_MAX_LINES][MENU_LINE_LENGTH];
|
extern uint16_t s_menu_count;
|
||||||
extern uint8_t s_menu_count;
|
|
||||||
extern uint8_t s_menu_flags;
|
extern uint8_t s_menu_flags;
|
||||||
extern uint8_t s_menu_offset;
|
extern uint16_t s_menu_offset;
|
||||||
const char * displayMenu(uint8_t event);
|
const char * displayMenu(uint8_t event);
|
||||||
|
|
||||||
#define STATUS_LINE_LENGTH 32
|
#define STATUS_LINE_LENGTH 32
|
||||||
|
|||||||
+66
-40
@@ -107,7 +107,7 @@ inline uint8_t eeFindEmptyModel(uint8_t id, bool down)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
bool listSdFiles(const char *path, const char *extension)
|
bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen, const char *selection)
|
||||||
{
|
{
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
DIR dir;
|
DIR dir;
|
||||||
@@ -118,23 +118,40 @@ bool listSdFiles(const char *path, const char *extension)
|
|||||||
fno.lfsize = sizeof(lfn);
|
fno.lfsize = sizeof(lfn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static uint16_t s_last_menu_offset = 0;
|
||||||
|
|
||||||
|
#if defined(PCBSKY9X)
|
||||||
|
if (selection) {
|
||||||
|
memset(reusableBuffer.models.menu_bss, 0, sizeof(reusableBuffer.models.menu_bss));
|
||||||
|
strcpy(reusableBuffer.models.menu_bss[0], path);
|
||||||
|
strcat(reusableBuffer.models.menu_bss[0], "/");
|
||||||
|
strncat(reusableBuffer.models.menu_bss[0], selection, maxlen);
|
||||||
|
strcat(reusableBuffer.models.menu_bss[0], SOUNDS_EXT);
|
||||||
|
if (f_stat(reusableBuffer.models.menu_bss[0], &fno) != FR_OK) {
|
||||||
|
selection = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (s_menu_offset == 0) {
|
||||||
|
s_last_menu_offset = 0;
|
||||||
|
memset(reusableBuffer.models.menu_bss, 0, sizeof(reusableBuffer.models.menu_bss));
|
||||||
|
}
|
||||||
|
else if (s_menu_offset == s_last_menu_offset) {
|
||||||
|
return true; // should not happen, only there because of Murphy's law
|
||||||
|
}
|
||||||
|
else if (s_menu_offset > s_last_menu_offset) {
|
||||||
|
memmove(reusableBuffer.models.menu_bss[0], reusableBuffer.models.menu_bss[1], (MENU_MAX_LINES-1)*MENU_LINE_LENGTH);
|
||||||
|
memset(reusableBuffer.models.menu_bss[MENU_MAX_LINES-1], 0xff, MENU_LINE_LENGTH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memmove(reusableBuffer.models.menu_bss[1], reusableBuffer.models.menu_bss[0], (MENU_MAX_LINES-1)*MENU_LINE_LENGTH);
|
||||||
|
memset(reusableBuffer.models.menu_bss[0], 0, MENU_LINE_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
s_menu_count = 0;
|
s_menu_count = 0;
|
||||||
s_menu_flags = BSS;
|
s_menu_flags = BSS;
|
||||||
|
|
||||||
static uint16_t s_last_menu_offset = 65535;
|
|
||||||
char hidden_line[MENU_LINE_LENGTH] = "";
|
|
||||||
|
|
||||||
if (s_menu_offset == 0)
|
|
||||||
s_last_menu_offset = 0;
|
|
||||||
/* else if (s_menu_offset >= s_menu_count-MENU_MAX_LINES)
|
|
||||||
s_last_menu_offset = s_menu_offset+1; */
|
|
||||||
else if (s_menu_offset > s_last_menu_offset)
|
|
||||||
memcpy(hidden_line, s_bss_menu[0], MENU_LINE_LENGTH);
|
|
||||||
else
|
|
||||||
memcpy(hidden_line, s_bss_menu[MENU_MAX_LINES-1], MENU_LINE_LENGTH);
|
|
||||||
|
|
||||||
memset(s_bss_menu, 0, sizeof(s_bss_menu));
|
|
||||||
|
|
||||||
FRESULT res = f_opendir(&dir, path); /* Open the directory */
|
FRESULT res = f_opendir(&dir, path); /* Open the directory */
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -148,39 +165,48 @@ bool listSdFiles(const char *path, const char *extension)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t len = strlen(fn);
|
uint8_t len = strlen(fn);
|
||||||
if (len < 5 || strcmp(fn+len-4, extension) || (fno.fattrib & AM_DIR)) continue;
|
if (len < 5 || len > maxlen+4 || strcmp(fn+len-4, extension) || (fno.fattrib & AM_DIR)) continue;
|
||||||
|
|
||||||
fn[len-4] = '\0';
|
|
||||||
s_menu_count++;
|
s_menu_count++;
|
||||||
|
fn[len-4] = '\0';
|
||||||
|
|
||||||
for (uint8_t i=0; i<MENU_MAX_LINES; i++) {
|
if (s_menu_offset == 0) {
|
||||||
char *line;
|
if (selection && strncmp(fn, selection, maxlen) < 0) {
|
||||||
if (s_menu_offset >= s_last_menu_offset) {
|
s_last_menu_offset++;
|
||||||
line = s_bss_menu[i];
|
|
||||||
if ((!hidden_line[0] || (strcmp(hidden_line, fn) < 0)) && (line[0] == '\0' || strcmp(fn, line) < 0)) {
|
|
||||||
if (i < MENU_MAX_LINES-1)
|
|
||||||
memmove(s_bss_menu[i+1], line, sizeof(s_bss_menu[i]) * (MENU_MAX_LINES-1-i));
|
|
||||||
strcpy(line, fn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
line = s_bss_menu[MENU_MAX_LINES-1-i];
|
for (uint8_t i=0; i<MENU_MAX_LINES; i++) {
|
||||||
if ((!hidden_line[0] || (strcmp(hidden_line, fn) > 0)) && (line[0] == '\0' || strcmp(fn, line) > 0)) {
|
char *line = reusableBuffer.models.menu_bss[i];
|
||||||
if (i < MENU_MAX_LINES-1)
|
if (line[0] == '\0' || strcmp(fn, line) < 0) {
|
||||||
memmove(s_bss_menu, s_bss_menu[1], sizeof(s_bss_menu[0]) * (MENU_MAX_LINES-1-i));
|
if (i < MENU_MAX_LINES-1) memmove(reusableBuffer.models.menu_bss[i+1], line, sizeof(reusableBuffer.models.menu_bss[i]) * (MENU_MAX_LINES-1-i));
|
||||||
strcpy(line, fn);
|
memset(line, 0, MENU_LINE_LENGTH);
|
||||||
break;
|
strcpy(line, fn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (uint8_t i=0; i<min(s_menu_count, (uint16_t)MENU_MAX_LINES); i++)
|
||||||
|
s_menu[i] = reusableBuffer.models.menu_bss[i];
|
||||||
|
}
|
||||||
|
else if (s_menu_offset > s_last_menu_offset) {
|
||||||
|
if (strcmp(fn, reusableBuffer.models.menu_bss[MENU_MAX_LINES-2]) > 0 && strcmp(fn, reusableBuffer.models.menu_bss[MENU_MAX_LINES-1]) < 0) {
|
||||||
|
memset(reusableBuffer.models.menu_bss[MENU_MAX_LINES-1], 0, MENU_LINE_LENGTH);
|
||||||
|
strcpy(reusableBuffer.models.menu_bss[MENU_MAX_LINES-1], fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (strcmp(fn, reusableBuffer.models.menu_bss[1]) < 0 && strcmp(fn, reusableBuffer.models.menu_bss[0]) > 0) {
|
||||||
|
memset(reusableBuffer.models.menu_bss[0], 0, MENU_LINE_LENGTH);
|
||||||
|
strcpy(reusableBuffer.models.menu_bss[0], fn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i=0; i<min(s_menu_count, (uint8_t)MENU_MAX_LINES); i++)
|
|
||||||
s_menu[i] = s_bss_menu[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s_last_menu_offset = s_menu_offset;
|
if (s_menu_offset > 0)
|
||||||
|
s_last_menu_offset = s_menu_offset;
|
||||||
|
else
|
||||||
|
s_menu_offset = s_last_menu_offset;
|
||||||
|
|
||||||
return s_menu_count;
|
return s_menu_count;
|
||||||
}
|
}
|
||||||
@@ -473,7 +499,7 @@ void menuModelSelect(uint8_t event)
|
|||||||
s_warning = eeBackupModel(sub);
|
s_warning = eeBackupModel(sub);
|
||||||
}
|
}
|
||||||
else if (result == STR_RESTORE_MODEL || result == STR_UPDATE_LIST) {
|
else if (result == STR_RESTORE_MODEL || result == STR_UPDATE_LIST) {
|
||||||
if (!listSdFiles(MODELS_PATH, MODELS_EXT)) {
|
if (!listSdFiles(MODELS_PATH, MODELS_EXT, 10, NULL)) {
|
||||||
s_warning = STR_NO_MODELS_ON_SD;
|
s_warning = STR_NO_MODELS_ON_SD;
|
||||||
s_menu_flags = 0;
|
s_menu_flags = 0;
|
||||||
}
|
}
|
||||||
@@ -2603,7 +2629,7 @@ void menuModelFunctionSwitches(uint8_t event)
|
|||||||
lcd_putsiAtt(15*FW, y, STR_VCSWFUNC, 0, attr);
|
lcd_putsiAtt(15*FW, y, STR_VCSWFUNC, 0, attr);
|
||||||
if (active && event==EVT_KEY_BREAK(KEY_MENU)) {
|
if (active && event==EVT_KEY_BREAK(KEY_MENU)) {
|
||||||
s_editMode = 0;
|
s_editMode = 0;
|
||||||
if (!listSdFiles(SOUNDS_PATH, SOUNDS_EXT)) {
|
if (!listSdFiles(SOUNDS_PATH, SOUNDS_EXT, 6, sd->param)) {
|
||||||
s_warning = STR_NO_SOUNDS_ON_SD;
|
s_warning = STR_NO_SOUNDS_ON_SD;
|
||||||
s_menu_flags = 0;
|
s_menu_flags = 0;
|
||||||
}
|
}
|
||||||
@@ -2685,7 +2711,7 @@ void menuModelFunctionSwitches(uint8_t event)
|
|||||||
const char * result = displayMenu(_event);
|
const char * result = displayMenu(_event);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result == STR_UPDATE_LIST) {
|
if (result == STR_UPDATE_LIST) {
|
||||||
if (!listSdFiles(SOUNDS_PATH, SOUNDS_EXT)) {
|
if (!listSdFiles(SOUNDS_PATH, SOUNDS_EXT, 6, NULL)) {
|
||||||
s_warning = STR_NO_SOUNDS_ON_SD;
|
s_warning = STR_NO_SOUNDS_ON_SD;
|
||||||
s_menu_flags = 0;
|
s_menu_flags = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -174,6 +174,8 @@ PACK(typedef struct t_EEGeneral {
|
|||||||
|
|
||||||
// eeprom modelspec
|
// eeprom modelspec
|
||||||
|
|
||||||
|
#define LEN_MODEL_NAME 10
|
||||||
|
|
||||||
#if defined(PCBX9D)
|
#if defined(PCBX9D)
|
||||||
#define LEN_EXPOMIX_NAME 10
|
#define LEN_EXPOMIX_NAME 10
|
||||||
#define LEN_FP_NAME 10
|
#define LEN_FP_NAME 10
|
||||||
@@ -718,7 +720,7 @@ PACK(typedef struct t_TimerDataExtra {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PACK(typedef struct t_ModelData {
|
PACK(typedef struct t_ModelData {
|
||||||
char name[10]; // must be first for eeLoadModelName
|
char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName
|
||||||
TimerData timers[MAX_TIMERS];
|
TimerData timers[MAX_TIMERS];
|
||||||
uint8_t protocol:3;
|
uint8_t protocol:3;
|
||||||
uint8_t thrTrim:1; // Enable Throttle Trim
|
uint8_t thrTrim:1; // Enable Throttle Trim
|
||||||
|
|||||||
+7
-1
@@ -1564,7 +1564,11 @@ void resetTimer(uint8_t idx)
|
|||||||
|
|
||||||
void resetAll()
|
void resetAll()
|
||||||
{
|
{
|
||||||
AUDIO_RESET();
|
static bool firstReset = true;
|
||||||
|
if (firstReset)
|
||||||
|
firstReset = false;
|
||||||
|
else
|
||||||
|
AUDIO_RESET();
|
||||||
|
|
||||||
resetTimer(0);
|
resetTimer(0);
|
||||||
resetTimer(1);
|
resetTimer(1);
|
||||||
@@ -1745,6 +1749,8 @@ void testFunc()
|
|||||||
#ifdef SIMU
|
#ifdef SIMU
|
||||||
printf("testFunc\n"); fflush(stdout);
|
printf("testFunc\n"); fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
while (1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+12
-7
@@ -154,8 +154,8 @@ typedef const int8_t pm_int8_t;
|
|||||||
#define pgm_read_adr(x) *(x)
|
#define pgm_read_adr(x) *(x)
|
||||||
#define cli()
|
#define cli()
|
||||||
#define sei()
|
#define sei()
|
||||||
#define wdt_disable() WDT->WDT_MR = WDT_MR_WDDIS;
|
#define wdt_disable()
|
||||||
#define wdt_enable(x) WDT->WDT_MR = 0x3FFF2FFF
|
#define wdt_enable(x) WDT->WDT_MR = 0x3FFF217F;
|
||||||
#define wdt_reset() WDT->WDT_CR = 0xA5000001
|
#define wdt_reset() WDT->WDT_CR = 0xA5000001
|
||||||
extern void board_init();
|
extern void board_init();
|
||||||
#else
|
#else
|
||||||
@@ -1166,23 +1166,28 @@ union ReusableBuffer
|
|||||||
/* 128 bytes on stock */
|
/* 128 bytes on stock */
|
||||||
|
|
||||||
#if !defined(PCBSKY9X)
|
#if !defined(PCBSKY9X)
|
||||||
uint8_t eefs_buffer[BLOCKS]; // used by EeFsck
|
uint8_t eefs_buffer[BLOCKS]; // 128bytes used by EeFsck
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
char mainname[42]; // used by menuModelSelect and for SD card archive / restore
|
char mainname[42];
|
||||||
char listnames[7][10];
|
char listnames[7][LEN_MODEL_NAME];
|
||||||
uint16_t listsizes[7];
|
uint16_t listsizes[7];
|
||||||
uint16_t eepromfree;
|
uint16_t eepromfree;
|
||||||
} models;
|
|
||||||
|
#if defined(SDCARD)
|
||||||
|
char menu_bss[MENU_MAX_LINES][MENU_LINE_LENGTH];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} models; // 128bytes used by menuModelSelect (mainname reused for SD card archive / restore)
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int16_t midVals[7];
|
int16_t midVals[7];
|
||||||
int16_t loVals[7];
|
int16_t loVals[7];
|
||||||
int16_t hiVals[7];
|
int16_t hiVals[7];
|
||||||
} calib; // used by menuGeneralCalib
|
} calib; // 42 bytes used by menuGeneralCalib
|
||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
struct
|
struct
|
||||||
|
|||||||
+5
-3
@@ -35,6 +35,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
volatile uint8_t pinb=0xff, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0;
|
volatile uint8_t pinb=0xff, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0;
|
||||||
uint8_t portb, portc, porth=0, dummyport;
|
uint8_t portb, portc, porth=0, dummyport;
|
||||||
@@ -294,9 +295,11 @@ namespace simu {
|
|||||||
FATFS g_FATFS_Obj;
|
FATFS g_FATFS_Obj;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FRESULT f_stat (const TCHAR*, FILINFO*)
|
FRESULT f_stat (const TCHAR * path, FILINFO *)
|
||||||
{
|
{
|
||||||
return FR_OK;
|
struct stat tmp;
|
||||||
|
// printf("f_stat(%s)\n", path); fflush(stdout);
|
||||||
|
return stat(path, &tmp) ? FR_INVALID_NAME : FR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
FRESULT f_mount (BYTE, FATFS*)
|
FRESULT f_mount (BYTE, FATFS*)
|
||||||
@@ -312,7 +315,6 @@ FRESULT f_open (FIL * fil, const TCHAR *name, BYTE)
|
|||||||
|
|
||||||
FRESULT f_read (FIL*, void*, UINT, UINT*)
|
FRESULT f_read (FIL*, void*, UINT, UINT*)
|
||||||
{
|
{
|
||||||
|
|
||||||
return FR_OK;
|
return FR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+43
-1
@@ -82,6 +82,49 @@ void dump(unsigned char *data, unsigned int size)
|
|||||||
debugPuts("\n\r");
|
debugPuts("\n\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures a UART peripheral with the specified parameters.
|
||||||
|
*
|
||||||
|
* baudrate Baudrate at which the UART should operate (in Hz).
|
||||||
|
* masterClock Frequency of the system master clock (in Hz).
|
||||||
|
* uses PA9 and PA10, RXD2 and TXD2
|
||||||
|
*/
|
||||||
|
void DEBUG_UART_Configure( uint32_t baudrate, uint32_t masterClock)
|
||||||
|
{
|
||||||
|
register Uart *pUart = CONSOLE_USART;
|
||||||
|
|
||||||
|
/* Configure PIO */
|
||||||
|
configure_pins( (PIO_PA9 | PIO_PA10), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||||
|
|
||||||
|
/* Configure PMC */
|
||||||
|
PMC->PMC_PCER0 = 1 << CONSOLE_ID;
|
||||||
|
|
||||||
|
/* Reset and disable receiver & transmitter */
|
||||||
|
pUart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
|
||||||
|
| UART_CR_RXDIS | UART_CR_TXDIS;
|
||||||
|
|
||||||
|
/* Configure mode */
|
||||||
|
pUart->UART_MR = 0x800 ; // NORMAL, No Parity
|
||||||
|
|
||||||
|
/* Configure baudrate */
|
||||||
|
/* Asynchronous, no oversampling */
|
||||||
|
pUart->UART_BRGR = (masterClock / baudrate) / 16;
|
||||||
|
|
||||||
|
/* Disable PDC channel */
|
||||||
|
pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||||
|
|
||||||
|
/* Enable receiver and transmitter */
|
||||||
|
pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||||
|
pUart->UART_IER = UART_IER_RXRDY ;
|
||||||
|
NVIC_EnableIRQ(UART0_IRQn) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DEBUG_UART_Stop()
|
||||||
|
{
|
||||||
|
CONSOLE_USART->UART_IDR = UART_IDR_RXRDY ;
|
||||||
|
NVIC_DisableIRQ(UART0_IRQn) ;
|
||||||
|
}
|
||||||
|
|
||||||
Fifo32 debugFifo;
|
Fifo32 debugFifo;
|
||||||
|
|
||||||
extern "C" void UART0_IRQHandler()
|
extern "C" void UART0_IRQHandler()
|
||||||
@@ -89,7 +132,6 @@ extern "C" void UART0_IRQHandler()
|
|||||||
debugFifo.push(CONSOLE_USART->UART_RHR);
|
debugFifo.push(CONSOLE_USART->UART_RHR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void debugTask(void* pdata)
|
void debugTask(void* pdata)
|
||||||
{
|
{
|
||||||
uint8_t rxchar ;
|
uint8_t rxchar ;
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#ifndef debug_h
|
#ifndef debug_h
|
||||||
#define debug_h
|
#define debug_h
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -57,6 +59,9 @@ void dump(unsigned char *data, unsigned int size);
|
|||||||
#define TRACE_ERROR(...) debugPuts("-E- " __VA_ARGS__)
|
#define TRACE_ERROR(...) debugPuts("-E- " __VA_ARGS__)
|
||||||
#define DUMP(data, size) dump(data, size)
|
#define DUMP(data, size) dump(data, size)
|
||||||
|
|
||||||
|
void DEBUG_UART_Configure( uint32_t baudrate, uint32_t masterClock);
|
||||||
|
void DEBUG_UART_Stop();
|
||||||
|
|
||||||
void debugTask(void* pdata);
|
void debugTask(void* pdata);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -70,6 +75,9 @@ void debugTask(void* pdata);
|
|||||||
#define TRACE_ERROR(...) { }
|
#define TRACE_ERROR(...) { }
|
||||||
#define DUMP(...) { }
|
#define DUMP(...) { }
|
||||||
|
|
||||||
|
#define DEBUG_UART_Configure(...)
|
||||||
|
#define DEBUG_UART_Stop(...)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-66
@@ -86,9 +86,7 @@ uint32_t Card_SCR[2] ;
|
|||||||
uint32_t Card_CSD[4] ;
|
uint32_t Card_CSD[4] ;
|
||||||
int32_t Card_state = SD_ST_STARTUP ;
|
int32_t Card_state = SD_ST_STARTUP ;
|
||||||
volatile uint32_t Card_initialized = 0;
|
volatile uint32_t Card_initialized = 0;
|
||||||
uint32_t Sd_128_resp[4] ;
|
|
||||||
uint32_t Sd_rca ;
|
uint32_t Sd_rca ;
|
||||||
uint32_t Cmd_8_resp ;
|
|
||||||
uint32_t Cmd_A41_resp ;
|
uint32_t Cmd_A41_resp ;
|
||||||
uint8_t cardType;
|
uint8_t cardType;
|
||||||
uint32_t transSpeed;
|
uint32_t transSpeed;
|
||||||
@@ -1102,8 +1100,6 @@ uint32_t sd_card_mounted( void )
|
|||||||
|
|
||||||
uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
|
uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
|
||||||
// int32_t retry;
|
|
||||||
unsigned int status = 0;
|
unsigned int status = 0;
|
||||||
|
|
||||||
// TRACE_ERROR("read block %d", block_no);
|
// TRACE_ERROR("read block %d", block_no);
|
||||||
@@ -1132,24 +1128,24 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if ((HSMCI->HSMCI_SR & (HSMCI_SR_ENDRX|HSMCI_SR_XFRDONE)) == (HSMCI_SR_ENDRX|HSMCI_SR_XFRDONE)) {
|
if ((HSMCI->HSMCI_SR & (HSMCI_SR_ENDRX|HSMCI_SR_XFRDONE)) == (HSMCI_SR_ENDRX|HSMCI_SR_XFRDONE)) {
|
||||||
result = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable PDC */
|
/* Disable PDC */
|
||||||
HSMCI->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
|
HSMCI->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
|
||||||
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
|
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// TRACE_ERROR("ok %.2X %.4Xd\n\r", HSMCI->HSMCI_SR, HSMCI->HSMCI_RSPR[0]);
|
// TRACE_ERROR("ok %.2X %.4Xd\n\r", HSMCI->HSMCI_SR, HSMCI->HSMCI_RSPR[0]);
|
||||||
|
|
||||||
return result;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
|
||||||
unsigned int status = 0;
|
unsigned int status = 0;
|
||||||
|
|
||||||
if (sd_card_ready()) {
|
if (sd_card_ready()) {
|
||||||
@@ -1167,7 +1163,6 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
|||||||
HSMCI->HSMCI_ARGR = (Cmd_A41_resp & OCR_SD_CCS ? block_no : (block_no << 9));
|
HSMCI->HSMCI_ARGR = (Cmd_A41_resp & OCR_SD_CCS ? block_no : (block_no << 9));
|
||||||
HSMCI->HSMCI_TPR = (uint32_t)data;
|
HSMCI->HSMCI_TPR = (uint32_t)data;
|
||||||
HSMCI->HSMCI_TCR = 512 / 4;
|
HSMCI->HSMCI_TCR = 512 / 4;
|
||||||
// HSMCI->HSMCI_PTCR = HSMCI_PTCR_TXTEN;
|
|
||||||
HSMCI->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK;
|
HSMCI->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK;
|
||||||
|
|
||||||
while (!(HSMCI->HSMCI_SR & HSMCI_SR_CMDRDY));
|
while (!(HSMCI->HSMCI_SR & HSMCI_SR_CMDRDY));
|
||||||
@@ -1178,17 +1173,18 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if ((HSMCI->HSMCI_SR & (HSMCI_SR_NOTBUSY|HSMCI_SR_XFRDONE)) == (HSMCI_SR_NOTBUSY|HSMCI_SR_XFRDONE)) {
|
if ((HSMCI->HSMCI_SR & (HSMCI_SR_NOTBUSY|HSMCI_SR_XFRDONE)) == (HSMCI_SR_NOTBUSY|HSMCI_SR_XFRDONE)) {
|
||||||
result = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Disable PDC */
|
||||||
|
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
|
||||||
|
HSMCI->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable PDC */
|
return 0;
|
||||||
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
|
|
||||||
HSMCI->HSMCI_MR &= ~(uint32_t)HSMCI_MR_PDCMODE;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1237,54 +1233,6 @@ DSTATUS disk_initialize (
|
|||||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||||
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
if ( sd_card_ready() == 0 ) return RES_NOTRDY;
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
|
||||||
#if 0
|
|
||||||
BYTE n, cmd, ty, ocr[4];
|
|
||||||
|
|
||||||
|
|
||||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
|
||||||
|
|
||||||
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
|
|
||||||
|
|
||||||
power_on(); /* Force socket power on */
|
|
||||||
FCLK_SLOW();
|
|
||||||
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
|
|
||||||
|
|
||||||
ty = 0;
|
|
||||||
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
|
|
||||||
Timer1 = 100; /* Initialization timeout of 1000 msec */
|
|
||||||
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2? */
|
|
||||||
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi(); /* Get trailing return value of R7 resp */
|
|
||||||
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
|
|
||||||
while (Timer1 && send_cmd(ACMD41, 1UL << 30)); /* Wait for leaving idle state (ACMD41 with HCS bit) */
|
|
||||||
if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
|
|
||||||
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
|
|
||||||
ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { /* SDv1 or MMCv3 */
|
|
||||||
if (send_cmd(ACMD41, 0) <= 1) {
|
|
||||||
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
|
|
||||||
} else {
|
|
||||||
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
|
|
||||||
}
|
|
||||||
while (Timer1 && send_cmd(cmd, 0)); /* Wait for leaving idle state */
|
|
||||||
if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
|
|
||||||
ty = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CardType = ty;
|
|
||||||
deselect();
|
|
||||||
|
|
||||||
if (ty) { /* Initialization succeded */
|
|
||||||
Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
|
|
||||||
FCLK_FAST();
|
|
||||||
} else { /* Initialization failed */
|
|
||||||
power_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Stat;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user