Remove SKY9X target
This commit is contained in:
committed by
Peter Feerick
parent
5601bd53b2
commit
09c49e24ee
@@ -1,7 +1,7 @@
|
||||
include(CMakeForceCompiler)
|
||||
include(Bitmaps)
|
||||
|
||||
set(PCB_TYPES X9LITE X9LITES X7 XLITE XLITES X9D X9D+ X9E X10 X12S SKY9X 9XRPRO AR9X NV14)
|
||||
set(PCB_TYPES X9LITE X9LITES X7 XLITE XLITES X9D X9D+ X9E X10 X12S NV14)
|
||||
set(RADIO_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL CN TW)
|
||||
set(TTS_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL RU CN)
|
||||
|
||||
@@ -101,8 +101,6 @@ elseif(PCB STREQUAL NV14)
|
||||
include(targets/nv14/CMakeLists.txt)
|
||||
elseif(PCB STREQUAL X9E OR PCB STREQUAL X9D+ OR PCB STREQUAL X9D OR PCB STREQUAL X7 OR PCB STREQUAL X9LITE OR PCB STREQUAL X9LITES OR PCB STREQUAL XLITE OR PCB STREQUAL XLITES)
|
||||
include(targets/taranis/CMakeLists.txt)
|
||||
elseif(PCB STREQUAL SKY9X OR PCB STREQUAL 9XRPRO OR PCB STREQUAL AR9X)
|
||||
include(targets/sky9x/CMakeLists.txt)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown PCB '${PCB}'")
|
||||
endif()
|
||||
|
||||
@@ -197,10 +197,6 @@ const char * const audioFilenames[] = {
|
||||
"servoko",
|
||||
"rxko",
|
||||
"modelpwr",
|
||||
#if defined(PCBSKY9X)
|
||||
"highmah",
|
||||
"hightemp",
|
||||
#endif
|
||||
"error",
|
||||
"warning1",
|
||||
"warning2",
|
||||
@@ -1101,10 +1097,6 @@ void audioEvent(unsigned int index)
|
||||
audioQueue.playTone(2250, 80, 20, PLAY_REPEAT(2));
|
||||
break;
|
||||
case AU_TX_BATTERY_LOW:
|
||||
#if defined(PCBSKY9X)
|
||||
case AU_TX_MAH_HIGH:
|
||||
case AU_TX_TEMP_HIGH:
|
||||
#endif
|
||||
audioQueue.playTone(1950, 160, 20, PLAY_REPEAT(2), 1);
|
||||
audioQueue.playTone(2550, 160, 20, PLAY_REPEAT(2), -1);
|
||||
break;
|
||||
|
||||
@@ -572,10 +572,6 @@ void audioTimerCountdown(uint8_t timer, int value);
|
||||
#define AUDIO_WARNING1() AUDIO_BUZZER(audioEvent(AU_WARNING1), beep(3))
|
||||
#define AUDIO_WARNING2() AUDIO_BUZZER(audioEvent(AU_WARNING2), beep(2))
|
||||
#define AUDIO_TX_BATTERY_LOW() AUDIO_BUZZER(audioEvent(AU_TX_BATTERY_LOW), beep(4))
|
||||
#if defined(PCBSKY9X)
|
||||
#define AUDIO_TX_MAH_HIGH() audioEvent(AU_TX_MAH_HIGH)
|
||||
#define AUDIO_TX_TEMP_HIGH() audioEvent(AU_TX_TEMP_HIGH)
|
||||
#endif
|
||||
#define AUDIO_ERROR() AUDIO_BUZZER(audioEvent(AU_ERROR), beep(4))
|
||||
#define AUDIO_TIMER_COUNTDOWN(idx, val) audioTimerCountdown(idx, val)
|
||||
#define AUDIO_TIMER_ELAPSED(idx) AUDIO_BUZZER(audioEvent(AU_TIMER1_ELAPSED+idx), beep(3))
|
||||
|
||||
@@ -1171,13 +1171,11 @@ int cliDisplay(const char ** argv)
|
||||
serialPrint("volume = %d", getVolume());
|
||||
}
|
||||
#endif
|
||||
#if defined(STM32)
|
||||
else if (!strcmp(argv[1], "uid")) {
|
||||
char str[LEN_CPU_UID+1];
|
||||
getCPUUniqueID(str);
|
||||
serialPrint("uid = %s", str);
|
||||
}
|
||||
#endif
|
||||
else if (!strcmp(argv[1], "tim")) {
|
||||
int timerNumber;
|
||||
if (toInt(argv, 2, &timerNumber) > 0) {
|
||||
|
||||
@@ -42,7 +42,6 @@ class Debounce
|
||||
T debouncedState;
|
||||
};
|
||||
|
||||
#if defined(STM32)
|
||||
class PinDebounce: public Debounce<uint8_t>
|
||||
{
|
||||
public:
|
||||
@@ -51,6 +50,5 @@ class PinDebounce: public Debounce<uint8_t>
|
||||
return Debounce<uint8_t>::debounce(GPIO_ReadInputDataBit(GPIOx, GPIO_Pin));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // _DEBOUNCE_H_
|
||||
|
||||
@@ -97,10 +97,6 @@ extern coord_t lcdNextPos;
|
||||
#define DISPLAY_END (displayBuf + DISPLAY_BUFFER_SIZE)
|
||||
#define ASSERT_IN_DISPLAY(p) assert((p) >= displayBuf && (p) < DISPLAY_END)
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
extern volatile uint8_t lcdLock ;
|
||||
extern volatile uint32_t lcdInputs ;
|
||||
#endif
|
||||
|
||||
void lcdDrawChar(coord_t x, coord_t y, uint8_t c);
|
||||
void lcdDrawChar(coord_t x, coord_t y, uint8_t c, LcdFlags flags);
|
||||
|
||||
@@ -168,14 +168,6 @@ enum MenuModelSetupItems {
|
||||
ITEM_MODEL_SETUP_EXTERNAL_MODULE_PXX2_RECEIVER_2,
|
||||
ITEM_MODEL_SETUP_EXTERNAL_MODULE_PXX2_RECEIVER_3,
|
||||
|
||||
#if defined(PCBSKY9X) && defined(REVX)
|
||||
ITEM_MODEL_SETUP_EXTERNAL_MODULE_OUTPUT_TYPE,
|
||||
#endif
|
||||
#if defined(PCBSKY9X)
|
||||
ITEM_MODEL_SETUP_EXTRA_MODULE_LABEL,
|
||||
ITEM_MODEL_SETUP_EXTRA_MODULE_CHANNELS,
|
||||
ITEM_MODEL_SETUP_EXTRA_MODULE_BIND,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
@@ -207,8 +199,6 @@ enum MenuModelSetupItems {
|
||||
#if defined(HARDWARE_INTERNAL_MODULE) && defined(HARDWARE_EXTERNAL_MODULE)
|
||||
#define CURRENT_MODULE_EDITED(k) (k >= ITEM_MODEL_SETUP_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE)
|
||||
#define CURRENT_RECEIVER_EDITED(k) (k - (k >= ITEM_MODEL_SETUP_EXTERNAL_MODULE_LABEL ? ITEM_MODEL_SETUP_EXTERNAL_MODULE_PXX2_RECEIVER_1 : ITEM_MODEL_SETUP_INTERNAL_MODULE_PXX2_RECEIVER_1))
|
||||
#elif defined(PCBSKY9X)
|
||||
#define CURRENT_MODULE_EDITED(k) (k >= ITEM_MODEL_SETUP_EXTRA_MODULE_LABEL ? EXTRA_MODULE : EXTERNAL_MODULE)
|
||||
#elif defined(HARDWARE_INTERNAL_MODULE)
|
||||
#define CURRENT_MODULE_EDITED(k) (INTERNAL_MODULE)
|
||||
#define CURRENT_RECEIVER_EDITED(k) (k - ITEM_MODEL_SETUP_INTERNAL_MODULE_PXX2_RECEIVER_1)
|
||||
@@ -249,11 +239,7 @@ inline uint8_t MODULE_SUBTYPE_ROWS(int moduleIdx)
|
||||
g_model.timers[x].countdownBeep != COUNTDOWN_SILENT ? (uint8_t)1 \
|
||||
: (uint8_t)0
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define EXTRA_MODULE_ROWS LABEL(ExtraModule), 1, 2,
|
||||
#else
|
||||
#define EXTRA_MODULE_ROWS
|
||||
#endif
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define FUNCTION_SWITCHES_ROWS READONLY_ROW, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|3, NAVIGATION_LINE_BY_LINE|(NUM_FUNCTIONS_SWITCHES-1),
|
||||
@@ -925,11 +911,6 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
case ITEM_MODEL_SETUP_EXTRA_MODULE_LABEL:
|
||||
lcdDrawTextAlignedLeft(y, "RF Port 2 (PPM)");
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_LABEL:
|
||||
@@ -1226,9 +1207,6 @@ void menuModelSetup(event_t event)
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_INTERNAL_MODULE_CHANNELS:
|
||||
#endif
|
||||
#if defined(PCBSKY9X)
|
||||
case ITEM_MODEL_SETUP_EXTRA_MODULE_CHANNELS:
|
||||
#endif
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_CHANNELS:
|
||||
#endif
|
||||
@@ -1369,9 +1347,6 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
case ITEM_MODEL_SETUP_EXTRA_MODULE_BIND:
|
||||
#endif
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_INTERNAL_MODULE_NOT_ACCESS_RXNUM_BIND_RANGE:
|
||||
#endif
|
||||
@@ -1525,14 +1500,6 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X) && defined(REVX)
|
||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_OUTPUT_TYPE:
|
||||
{
|
||||
ModuleData & moduleData = g_model.moduleData[moduleIdx];
|
||||
moduleData.ppm.outputType = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_OUTPUT_TYPE, STR_VOUTPUT_TYPE, moduleData.ppm.outputType, 0, 1, attr, event);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_INTERNAL_MODULE_FAILSAFE:
|
||||
@@ -1933,12 +1900,6 @@ void menuModelSetup(event_t event)
|
||||
checkModelIdUnique(g_eeGeneral.currModel, INTERNAL_MODULE);
|
||||
break;
|
||||
#endif
|
||||
#if defined(PCBSKY9X)
|
||||
case ITEM_MODEL_SETUP_EXTRA_MODULE_BIND:
|
||||
if (menuHorizontalPosition == 0)
|
||||
checkModelIdUnique(g_eeGeneral.currModel, EXTRA_MODULE);
|
||||
break;
|
||||
#endif
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_NOT_ACCESS_RXNUM_BIND_RANGE:
|
||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_PXX2_MODEL_NUM:
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
|
||||
enum MenuModelTelemetryFrskyItems {
|
||||
ITEM_TELEMETRY_PROTOCOL_TYPE,
|
||||
#if defined(REVX)
|
||||
ITEM_TELEMETRY_INVERTED_SERIAL,
|
||||
#endif
|
||||
ITEM_TELEMETRY_RSSI_LABEL,
|
||||
ITEM_TELEMETRY_RSSI_SOURCE,
|
||||
ITEM_TELEMETRY_RSSI_ALARM1,
|
||||
@@ -70,11 +67,7 @@ enum MenuModelTelemetryFrskyItems {
|
||||
#define TELEMETRY_TYPE_ROW (g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_PPM) ? (uint8_t)0 : HIDDEN_ROW
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TELEMETRY_TYPE_ROWS TELEMETRY_TYPE_ROW, TELEMETRY_TYPE_ROW,
|
||||
#else
|
||||
#define TELEMETRY_TYPE_ROWS TELEMETRY_TYPE_ROW,
|
||||
#endif
|
||||
|
||||
void onSensorMenu(const char * result)
|
||||
{
|
||||
@@ -187,11 +180,6 @@ void menuModelTelemetry(event_t event)
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(REVX)
|
||||
case ITEM_TELEMETRY_INVERTED_SERIAL:
|
||||
g_model.moduleData[EXTERNAL_MODULE].invertedSerial = editCheckBox(g_model.moduleData[EXTERNAL_MODULE].invertedSerial, TELEM_COL2, y, STR_INVERTED_SERIAL, attr, event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_TELEMETRY_SENSORS_LABEL:
|
||||
lcdDrawTextAlignedLeft(y, STR_TELEMETRY_SENSORS);
|
||||
|
||||
@@ -41,8 +41,6 @@ void menuRadioDiagAnalogs(event_t event)
|
||||
// TODO enum
|
||||
#if defined(TX_CAPACITY_MEASUREMENT)
|
||||
#define ANAS_ITEMS_COUNT 3
|
||||
#elif defined(PCBSKY9X)
|
||||
#define ANAS_ITEMS_COUNT 2
|
||||
#else
|
||||
#define ANAS_ITEMS_COUNT 1
|
||||
#endif
|
||||
|
||||
@@ -63,13 +63,7 @@ void menuRadioDiagKeys(event_t event)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
if (i != SW_ID0) {
|
||||
y = MENU_HEADER_HEIGHT +i*FH - 2*FH;
|
||||
drawSwitch(8*FW, y, i+1, 0);
|
||||
displaySwitchState(11*FW+2, y, i);
|
||||
}
|
||||
#elif (NUM_SWITCHES > 6)
|
||||
#if (NUM_SWITCHES > 6)
|
||||
if (i < NUM_SWITCHES) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
y = (i > 4) ? FH*(i-4)+1 : MENU_HEADER_HEIGHT + FH*i + 1;
|
||||
|
||||
@@ -99,7 +99,7 @@ enum {
|
||||
ITEM_RADIO_SETUP_IMPERIAL,
|
||||
IF_FAI_CHOICE(ITEM_RADIO_SETUP_FAI)
|
||||
ITEM_RADIO_SETUP_SWITCHES_DELAY,
|
||||
CASE_STM32(ITEM_RADIO_SETUP_USB_MODE)
|
||||
ITEM_RADIO_SETUP_USB_MODE,
|
||||
CASE_JACK_DETECT(ITEM_RADIO_SETUP_JACK_MODE)
|
||||
ITEM_RADIO_SETUP_RX_CHANNEL_ORD,
|
||||
ITEM_RADIO_SETUP_STICK_MODE_LABELS,
|
||||
@@ -173,7 +173,7 @@ void menuRadioSetup(event_t event)
|
||||
CASE_PXX1(0)
|
||||
0, 0, IF_FAI_CHOICE(0)
|
||||
0,
|
||||
CASE_STM32(0) // USB mode
|
||||
0, // USB mode
|
||||
CASE_JACK_DETECT(0) // Jack mode
|
||||
0, COL_TX_MODE, 0, 1/*to force edit mode*/});
|
||||
|
||||
@@ -621,11 +621,9 @@ void menuRadioSetup(event_t event)
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.switchesDelay, -15, 100-15);
|
||||
break;
|
||||
|
||||
#if defined(STM32)
|
||||
case ITEM_RADIO_SETUP_USB_MODE:
|
||||
g_eeGeneral.USBMode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_USBMODE, STR_USBMODES, g_eeGeneral.USBMode, USB_UNSELECTED_MODE, USB_MAX_MODE, attr, event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(JACK_DETECT_GPIO)
|
||||
case ITEM_RADIO_SETUP_JACK_MODE:
|
||||
|
||||
@@ -277,20 +277,7 @@ void displayBattVoltage()
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
void displayVoltageOrAlarm()
|
||||
{
|
||||
if (g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.txCurrentCalibration)/8192/36) / 500 >= g_eeGeneral.mAhWarn) {
|
||||
drawValueWithUnit(7*FW-1, 2*FH, (g_eeGeneral.mAhUsed + Current_used*(488 + g_eeGeneral.txCurrentCalibration)/8192/36)/10, UNIT_MAH,
|
||||
BLINK|INVERS|DBLSIZE|RIGHT);
|
||||
}
|
||||
else {
|
||||
displayBattVoltage();
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define displayVoltageOrAlarm() displayBattVoltage()
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_T8)
|
||||
#define EVT_KEY_CONTEXT_MENU EVT_KEY_LONG(KEY_ENTER)
|
||||
|
||||
@@ -58,9 +58,7 @@ void menuStatisticsView(event_t event)
|
||||
#if !defined(PCBTARANIS)
|
||||
case EVT_KEY_LONG(KEY_MENU): // historical
|
||||
#endif
|
||||
#if !defined(PCBSKY9X)
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
#endif
|
||||
g_eeGeneral.globalTimer = 0;
|
||||
storageDirty(EE_GENERAL);
|
||||
sessionTimer = 0;
|
||||
@@ -122,10 +120,6 @@ void menuStatisticsDebug(event_t event)
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
#if defined(PCBSKY9X)
|
||||
g_eeGeneral.mAhUsed = 0;
|
||||
Current_used = 0;
|
||||
#endif
|
||||
g_eeGeneral.globalTimer = 0;
|
||||
sessionTimer = 0;
|
||||
storageDirty(EE_GENERAL);
|
||||
@@ -170,14 +164,6 @@ void menuStatisticsDebug(event_t event)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
if (IS_RESET_REASON_WATCHDOG()) {
|
||||
lcdDrawText(LCD_W-8*FW, 0, "WATCHDOG");
|
||||
}
|
||||
else if (globalData.unexpectedShutdown) {
|
||||
lcdDrawText(LCD_W-13*FW, 0, "UNEXP.SHTDOWN");
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t y = FH + 1;
|
||||
|
||||
@@ -214,12 +200,10 @@ void menuStatisticsDebug(event_t event)
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
lcdDrawTextAlignedLeft(y, "Free Mem");
|
||||
lcdDrawNumber(MENU_DEBUG_COL1_OFS, y, availableMemory(), LEFT);
|
||||
lcdDrawText(lcdLastRightPos, y, "b");
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
#if defined(LUA)
|
||||
lcdDrawTextAlignedLeft(y, "Lua scripts");
|
||||
@@ -256,7 +240,6 @@ void menuStatisticsDebug(event_t event)
|
||||
lcdInvertLastLine();
|
||||
}
|
||||
|
||||
#if defined(STM32)
|
||||
void menuStatisticsDebug2(event_t event)
|
||||
{
|
||||
title(STR_MENUDEBUG);
|
||||
@@ -305,4 +288,3 @@ void menuStatisticsDebug2(event_t event)
|
||||
lcdDrawText(LCD_W/2, 7*FH+1, STR_MENUTORESET, CENTERED);
|
||||
lcdInvertLastLine();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -88,10 +88,8 @@ enum {
|
||||
|
||||
ITEM_RADIO_HARDWARE_BATTERY_CALIB,
|
||||
|
||||
#if defined(STM32)
|
||||
ITEM_RADIO_HARDWARE_RTC_BATTERY,
|
||||
ITEM_RADIO_HARDWARE_RTC_CHECK,
|
||||
#endif
|
||||
|
||||
#if defined(TX_CAPACITY_MEASUREMENT)
|
||||
ITEM_RADIO_HARDWARE_CAPACITY_CALIB,
|
||||
@@ -217,11 +215,7 @@ enum {
|
||||
#define SWITCH_TYPE_MAX(sw) ((MIXSRC_SF - MIXSRC_FIRST_SWITCH == sw || MIXSRC_SH - MIXSRC_FIRST_SWITCH <= sw) ? SWITCH_2POS : SWITCH_3POS)
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
#define RTC_ROW READONLY_ROW, 0,
|
||||
#else
|
||||
#define RTC_ROW
|
||||
#endif
|
||||
|
||||
#if defined(TX_CAPACITY_MEASUREMENT)
|
||||
#define TX_CAPACITY_MEASUREMENT_ROWS 0,
|
||||
@@ -488,14 +482,6 @@ void menuRadioHardware(event_t event)
|
||||
#if defined(PCBTARANIS)
|
||||
lcdDrawTextAlignedLeft(y, STR_BATT_CALIB);
|
||||
putsVolts(HW_SETTINGS_COLUMN2, y, getBatteryVoltage(), attr|PREC2|LEFT);
|
||||
#elif defined(PCBSKY9X)
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT+1+4*FH, STR_BATT_CALIB);
|
||||
static int32_t adcBatt;
|
||||
// TODO board.cpp
|
||||
adcBatt = ((adcBatt * 7) + anaIn(TX_VOLTAGE)) / 8;
|
||||
uint32_t batCalV = (adcBatt + adcBatt*(g_eeGeneral.txVoltageCalibration)/128) * 4191;
|
||||
batCalV /= 55296;
|
||||
putsVolts(HW_SETTINGS_COLUMN2, y, batCalV, (menuVerticalPosition==HEADER_LINE ? INVERS : 0));
|
||||
#else
|
||||
lcdDrawTextAlignedLeft(MENU_HEADER_HEIGHT + 1 + (NUM_STICKS+NUM_POTS+NUM_SLIDERS+1)/2 * FH, STR_BATT_CALIB);
|
||||
putsVolts(HW_SETTINGS_COLUMN2, y, g_vbat100mV, attr|LEFT);
|
||||
@@ -505,7 +491,6 @@ void menuRadioHardware(event_t event)
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(STM32)
|
||||
case ITEM_RADIO_HARDWARE_RTC_BATTERY:
|
||||
lcdDrawTextAlignedLeft(y, STR_RTC_BATT);
|
||||
putsVolts(HW_SETTINGS_COLUMN2, y, getRTCBatteryVoltage(), PREC2|LEFT);
|
||||
@@ -514,7 +499,6 @@ void menuRadioHardware(event_t event)
|
||||
case ITEM_RADIO_HARDWARE_RTC_CHECK:
|
||||
g_eeGeneral.disableRtcWarning = 1 - editCheckBox(1 - g_eeGeneral.disableRtcWarning, HW_SETTINGS_COLUMN2, y, STR_RTC_CHECK, attr, event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(TX_CAPACITY_MEASUREMENT)
|
||||
case ITEM_RADIO_HARDWARE_CAPACITY_CALIB:
|
||||
@@ -686,4 +670,4 @@ void menuRadioHardware(event_t event)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PCBSKY9X
|
||||
#endif
|
||||
|
||||
@@ -83,9 +83,6 @@ void onSdFormatConfirm(const char * result)
|
||||
if (result == STR_OK) {
|
||||
showMessageBox(STR_FORMATTING);
|
||||
logsClose();
|
||||
#if defined(PCBSKY9X)
|
||||
Card_state = SD_ST_DATA;
|
||||
#endif
|
||||
audioQueue.stopSD();
|
||||
if (sdCardFormat()) {
|
||||
f_chdir(ROOT_PATH);
|
||||
|
||||
@@ -309,12 +309,6 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
||||
swtch = -swtch;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
if (swtch >= SWSRC_FIRST_SWITCH && swtch <= SWSRC_LAST_SWITCH) {
|
||||
UNUSED(negative);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (swtch >= SWSRC_FIRST_SWITCH && swtch <= SWSRC_LAST_SWITCH) {
|
||||
div_t swinfo = switchInfo(swtch);
|
||||
if (!SWITCH_EXISTS(swinfo.quot)) {
|
||||
@@ -328,7 +322,6 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NUM_XPOTS > 0
|
||||
if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH && swtch <= SWSRC_LAST_MULTIPOS_SWITCH) {
|
||||
@@ -824,7 +817,7 @@ bool isTrainerModeAvailable(int mode)
|
||||
#if defined(BLUETOOTH) && !defined(PCBX9E)
|
||||
if (g_eeGeneral.bluetoothMode != BLUETOOTH_TRAINER && (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH))
|
||||
return false;
|
||||
#elif !defined(PCBSKY9X)
|
||||
#else
|
||||
if (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
@@ -177,9 +177,6 @@ void killAllEvents()
|
||||
|
||||
bool waitKeysReleased()
|
||||
{
|
||||
#if defined(PCBSKY9X)
|
||||
RTOS_WAIT_MS(200); // 200ms
|
||||
#endif
|
||||
|
||||
// loop until all keys are up
|
||||
#if !defined(BOOT)
|
||||
|
||||
+1
-13
@@ -80,7 +80,7 @@ void openUsbMenu()
|
||||
#endif
|
||||
}
|
||||
|
||||
#elif defined(STM32)
|
||||
#else
|
||||
|
||||
void onUSBConnectMenu(const char *result)
|
||||
{
|
||||
@@ -286,11 +286,6 @@ void checkBatteryAlarms()
|
||||
AUDIO_TX_BATTERY_LOW();
|
||||
// TRACE("checkBatteryAlarms(): battery low");
|
||||
}
|
||||
#if defined(PCBSKY9X)
|
||||
else if (g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.txCurrentCalibration)/8192/36) / 500 >= g_eeGeneral.mAhWarn) { // TODO move calculation into board file
|
||||
AUDIO_TX_MAH_HIGH();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void checkBattery()
|
||||
@@ -480,9 +475,6 @@ void perMain()
|
||||
{
|
||||
DEBUG_TIMER_START(debugTimerPerMain1);
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
calcConsumption();
|
||||
#endif
|
||||
|
||||
checkSpeakerVolume();
|
||||
|
||||
@@ -520,12 +512,10 @@ void perMain()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
if ((!usbPlugged() || (getSelectedUsbMode() == USB_UNSELECTED_MODE))
|
||||
&& SD_CARD_PRESENT() && !sdMounted()) {
|
||||
sdMount();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(EEPROM)
|
||||
// In case the SD card is removed during the session
|
||||
@@ -540,7 +530,6 @@ void perMain()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
if (usbPlugged() && getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
|
||||
#if defined(LIBOPENUI)
|
||||
// draw some image showing USB
|
||||
@@ -555,7 +544,6 @@ void perMain()
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
checkFailsafeMulti();
|
||||
|
||||
@@ -260,11 +260,7 @@ enum SwashType {
|
||||
|
||||
#define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
#define TIMER_COUNTDOWN_START(x) (g_model.timers[x].countdownStart == 0 ? 20 : (g_model.timers[x].countdownStart == 1 ? 30 : (g_model.timers[x].countdownStart == -1 ? 10 : 5)))
|
||||
#else
|
||||
#define TIMER_COUNTDOWN_START(x) 10
|
||||
#endif
|
||||
|
||||
#include "pulses/modules_constants.h"
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
#include "view_text.h"
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#include "audio_driver.h"
|
||||
#endif
|
||||
|
||||
extern uint16_t get_flysky_hall_adc_value(uint8_t ch);
|
||||
|
||||
@@ -56,9 +53,7 @@ safetych_t safetyCh[MAX_OUTPUT_CHANNELS];
|
||||
// __DMA for the MSC_BOT_Data member
|
||||
union ReusableBuffer reusableBuffer __DMA;
|
||||
|
||||
#if defined(STM32)
|
||||
uint8_t* MSC_BOT_Data = reusableBuffer.MSC_BOT_Data;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_LATENCY)
|
||||
uint8_t latencyToggleSwitch = 0;
|
||||
@@ -602,11 +597,6 @@ void doSplash()
|
||||
resetBacklightTimeout();
|
||||
drawSplash();
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
tmr10ms_t curTime = get_tmr10ms() + 10;
|
||||
uint8_t contrast = 10;
|
||||
lcdSetRefVolt(contrast);
|
||||
#endif
|
||||
|
||||
getADC(); // init ADC array
|
||||
|
||||
@@ -640,15 +630,6 @@ void doSplash()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
if (curTime < get_tmr10ms()) {
|
||||
curTime += 10;
|
||||
if (contrast < g_eeGeneral.contrast) {
|
||||
contrast += 1;
|
||||
lcdSetRefVolt(contrast);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
checkBacklight();
|
||||
}
|
||||
@@ -675,7 +656,6 @@ void checkMultiLowPower()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
static void checkRTCBattery()
|
||||
{
|
||||
GET_ADC_IF_MIXER_NOT_RUNNING();
|
||||
@@ -683,7 +663,6 @@ static void checkRTCBattery()
|
||||
ALERT(STR_BATTERY, STR_WARN_RTC_BATTERY_LOW, AU_ERROR);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBFRSKY) || defined(PCBFLYSKY)
|
||||
static void checkFailsafe()
|
||||
@@ -718,13 +697,11 @@ void checkAll()
|
||||
checkFailsafe();
|
||||
|
||||
|
||||
#if defined(STM32)
|
||||
if (isVBatBridgeEnabled() && !g_eeGeneral.disableRtcWarning) {
|
||||
// only done once at board start
|
||||
checkRTCBattery();
|
||||
}
|
||||
disableVBatBridge();
|
||||
#endif
|
||||
|
||||
if (g_model.displayChecklist && modelHasNotes()) {
|
||||
readModelNotes();
|
||||
@@ -1290,11 +1267,6 @@ void doMixerCalculations()
|
||||
getSwitchesPosition(!s_mixer_first_run_done);
|
||||
DEBUG_TIMER_STOP(debugTimerGetSwitches);
|
||||
|
||||
#if defined(PCBSKY9X) && !defined(SIMU)
|
||||
Current_analogue = (Current_analogue*31 + s_anaFilt[8] ) >> 5 ;
|
||||
if (Current_analogue > Current_max)
|
||||
Current_max = Current_analogue ;
|
||||
#endif
|
||||
|
||||
|
||||
DEBUG_TIMER_START(debugTimerEvalMixes);
|
||||
@@ -1452,11 +1424,6 @@ void opentxStart(const uint8_t startOptions = OPENTX_START_DEFAULT_ARGS)
|
||||
trace_event(trace_start, 0x12345678);
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X) && defined(SDCARD) && !defined(SIMU)
|
||||
for (int i=0; i<500 && !Card_initialized; i++) {
|
||||
RTOS_WAIT_MS(2); // 2ms
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(TEST_BUILD_WARNING)
|
||||
ALERT(STR_TEST_WARNING, TR_TEST_NOTSAFE, AU_ERROR);
|
||||
@@ -1513,12 +1480,6 @@ void opentxClose(uint8_t shutdown)
|
||||
sessionTimer = 0;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
uint32_t mAhUsed = g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.txCurrentCalibration) / 8192 / 36;
|
||||
if (g_eeGeneral.mAhUsed != mAhUsed) {
|
||||
g_eeGeneral.mAhUsed = mAhUsed;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_eeGeneral.unexpectedShutdown = 0;
|
||||
storageDirty(EE_GENERAL);
|
||||
@@ -1550,7 +1511,6 @@ void opentxClose(uint8_t shutdown)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(STM32)
|
||||
void opentxResume()
|
||||
{
|
||||
TRACE("opentxResume");
|
||||
@@ -1583,7 +1543,6 @@ void opentxResume()
|
||||
storageDirty(EE_GENERAL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define INSTANT_TRIM_MARGIN 10 /* around 1% */
|
||||
|
||||
@@ -1918,14 +1877,7 @@ void opentxInit()
|
||||
audioQueue.start();
|
||||
BACKLIGHT_ENABLE();
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
// Set ADC gains here
|
||||
setSticksGain(g_eeGeneral.sticksGain);
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X) && defined(BLUETOOTH)
|
||||
btInit();
|
||||
#endif
|
||||
|
||||
#if defined(SPORT_UPDATE_PWR_GPIO)
|
||||
SPORT_UPDATE_POWER_INIT();
|
||||
@@ -1984,7 +1936,6 @@ int main()
|
||||
initialise_monitor_handles();
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
|
||||
#if !defined(SIMU)
|
||||
/* Ensure all priority bits are assigned as preemption priority bits. */
|
||||
@@ -1999,7 +1950,6 @@ int main()
|
||||
sizeof(reusableBuffer.hardwareAndSettings),
|
||||
sizeof(reusableBuffer.spectrumAnalyser),
|
||||
sizeof(reusableBuffer.MSC_BOT_Data));
|
||||
#endif
|
||||
|
||||
// G: The WDT remains active after a WDT reset -- at maximum clock speed. So it's
|
||||
// important to disable it before commencing with system initialisation (or
|
||||
|
||||
+1
-44
@@ -34,9 +34,7 @@
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#if defined(STM32)
|
||||
#include "usbd_conf.h"
|
||||
#endif
|
||||
|
||||
#if defined(LIBOPENUI)
|
||||
#include "libopenui.h"
|
||||
@@ -50,20 +48,6 @@
|
||||
#define SWITCH_SIMU(a, b) (b)
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define IS_PCBSKY9X true
|
||||
#define CASE_PCBSKY9X(x) x,
|
||||
#else
|
||||
#define IS_PCBSKY9X false
|
||||
#define CASE_PCBSKY9X(x)
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
#define CASE_STM32(x) x,
|
||||
#else
|
||||
#define CASE_STM32(x)
|
||||
#endif
|
||||
|
||||
#if defined(VARIO)
|
||||
#define CASE_VARIO(x) x,
|
||||
#else
|
||||
@@ -196,12 +180,7 @@
|
||||
#define CASE_PCBX9E(x)
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X) && !defined(PCBAR9X)
|
||||
#define TX_CAPACITY_MEASUREMENT
|
||||
#define CASE_CAPACITY(x) x,
|
||||
#else
|
||||
#define CASE_CAPACITY(x)
|
||||
#endif
|
||||
|
||||
#if defined(FAI)
|
||||
#define IS_FAI_ENABLED() true
|
||||
@@ -579,11 +558,7 @@ int getTrimValue(uint8_t phase, uint8_t idx);
|
||||
|
||||
bool setTrimValue(uint8_t phase, uint8_t idx, int trim);
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define ROTARY_ENCODER_GRANULARITY (2 << g_eeGeneral.rotarySteps)
|
||||
#else
|
||||
#define ROTARY_ENCODER_GRANULARITY (2)
|
||||
#endif
|
||||
|
||||
#include "gvars.h"
|
||||
|
||||
@@ -610,12 +585,8 @@ void flightReset(uint8_t check=true);
|
||||
#if defined(SIMU)
|
||||
uint16_t getTmr2MHz();
|
||||
uint16_t getTmr16KHz();
|
||||
#elif defined(STM32)
|
||||
static inline uint16_t getTmr2MHz() { return TIMER_2MHz_TIMER->CNT; }
|
||||
#elif defined(PCBSKY9X)
|
||||
static inline uint16_t getTmr2MHz() { return TC1->TC_CHANNEL[0].TC_CV; }
|
||||
#else
|
||||
uint16_t getTmr16KHz();
|
||||
static inline uint16_t getTmr2MHz() { return TIMER_2MHz_TIMER->CNT; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -875,10 +846,6 @@ enum AUDIO_SOUNDS {
|
||||
AU_SERVO_KO,
|
||||
AU_RX_OVERLOAD,
|
||||
AU_MODEL_STILL_POWERED,
|
||||
#if defined(PCBSKY9X)
|
||||
AU_TX_MAH_HIGH,
|
||||
AU_TX_TEMP_HIGH,
|
||||
#endif
|
||||
AU_ERROR,
|
||||
AU_WARNING1,
|
||||
AU_WARNING2,
|
||||
@@ -962,10 +929,6 @@ enum AUDIO_SOUNDS {
|
||||
#include "rtc.h"
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
void setMFP();
|
||||
void clearMFP();
|
||||
#endif
|
||||
|
||||
void checkBattery();
|
||||
void opentxClose(uint8_t shutdown=true);
|
||||
@@ -1060,12 +1023,10 @@ union ReusableBuffer
|
||||
} sdManager;
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
struct
|
||||
{
|
||||
char id[27];
|
||||
} version;
|
||||
#endif
|
||||
|
||||
// moduleOptions, receiverOptions, radioVersion
|
||||
PXX2HardwareAndSettings hardwareAndSettings;
|
||||
@@ -1141,10 +1102,8 @@ union ReusableBuffer
|
||||
ModuleInformation internalModule;
|
||||
} viewMain;
|
||||
|
||||
#if defined(STM32)
|
||||
// Data for the USB mass storage driver. If USB mass storage runs no menu is not allowed to be displayed
|
||||
uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET];
|
||||
#endif
|
||||
};
|
||||
|
||||
extern ReusableBuffer reusableBuffer;
|
||||
@@ -1224,9 +1183,7 @@ void varioWakeup();
|
||||
extern const unsigned char logo_taranis[];
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
void usbPluggedIn();
|
||||
#endif
|
||||
|
||||
#include "lua/lua_api.h"
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#define DSM2_SEND_BIND (1 << 7)
|
||||
#define DSM2_SEND_RANGECHECK (1 << 5)
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
|
||||
#endif
|
||||
|
||||
// DSM2 control bits
|
||||
#define DSM2_CHANS 6
|
||||
@@ -135,28 +132,12 @@ void setupPulsesDSM2()
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
if (dsm2BindTimer > 0) {
|
||||
dsm2BindTimer--;
|
||||
if (switchState(SW_DSM2_BIND)) {
|
||||
moduleState[EXTERNAL_MODULE].mode = MODULE_MODE_BIND;
|
||||
dsmDat[0] |= DSM2_SEND_BIND;
|
||||
}
|
||||
}
|
||||
else if (moduleState[EXTERNAL_MODULE].mode == MODULE_MODE_RANGECHECK) {
|
||||
dsmDat[0] |= DSM2_SEND_RANGECHECK;
|
||||
}
|
||||
else {
|
||||
moduleState[EXTERNAL_MODULE].mode = 0;
|
||||
}
|
||||
#else
|
||||
if (moduleState[EXTERNAL_MODULE].mode == MODULE_MODE_BIND) {
|
||||
dsmDat[0] |= DSM2_SEND_BIND;
|
||||
}
|
||||
else if (moduleState[EXTERNAL_MODULE].mode == MODULE_MODE_RANGECHECK) {
|
||||
dsmDat[0] |= DSM2_SEND_RANGECHECK;
|
||||
}
|
||||
#endif
|
||||
|
||||
dsmDat[1] = g_model.header.modelId[EXTERNAL_MODULE]; // DSM2 Header second byte for model match
|
||||
|
||||
|
||||
@@ -244,17 +244,10 @@ inline bool isModuleGhost(uint8_t idx)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
inline bool isExtraModule(uint8_t idx)
|
||||
{
|
||||
return idx == EXTRA_MODULE;
|
||||
}
|
||||
#else
|
||||
inline bool isExtraModule(uint8_t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline bool isModuleTypePPM(uint8_t type)
|
||||
{
|
||||
@@ -263,10 +256,6 @@ inline bool isModuleTypePPM(uint8_t type)
|
||||
|
||||
inline bool isModulePPM(uint8_t moduleIdx)
|
||||
{
|
||||
#if defined(PCBSKY9X)
|
||||
if (moduleIdx == EXTRA_MODULE)
|
||||
return true;
|
||||
#endif
|
||||
return isModuleTypePPM(g_model.moduleData[moduleIdx].type);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,32 +33,18 @@ void setupPulsesPPM(PpmPulsesData<T> * ppmPulsesData, uint8_t channelsStart, int
|
||||
uint8_t firstCh = channelsStart;
|
||||
uint8_t lastCh = min<uint8_t>(MAX_OUTPUT_CHANNELS, firstCh + 8 + channelsCount);
|
||||
|
||||
#if defined(STM32)
|
||||
ppmPulsesData->ptr = ppmPulsesData->pulses;
|
||||
#else
|
||||
uint16_t * ptr = ppmPulsesData->pulses;
|
||||
ppmPulsesData->ptr = ptr;
|
||||
#endif
|
||||
|
||||
int32_t rest = 22500u * 2;
|
||||
rest += int32_t(frameLength) * 1000;
|
||||
for (uint32_t i=firstCh; i<lastCh; i++) {
|
||||
int16_t v = limit((int16_t)-PPM_range, channelOutputs[i], (int16_t)PPM_range) + 2*PPM_CH_CENTER(i);
|
||||
rest -= v;
|
||||
#if defined(STM32)
|
||||
*ppmPulsesData->ptr++ = v; /* as Pat MacKenzie suggests */
|
||||
#else
|
||||
*ptr++ = v; /* as Pat MacKenzie suggests */
|
||||
#endif
|
||||
}
|
||||
rest = limit<int32_t>(9000, rest, 65535); /* avoids that CCR2 is bigger than ARR which would cause reboot */
|
||||
#if defined(STM32)
|
||||
*ppmPulsesData->ptr++ = rest;
|
||||
*ppmPulsesData->ptr = 0; // it's needed in case PPM is sent without DMA (we stop when we reach this 0)
|
||||
#else
|
||||
*ptr = rest;
|
||||
*(ptr + 1) = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void setupPulsesPPMTrainer()
|
||||
|
||||
@@ -296,12 +296,8 @@ void enablePulsesExternalModule(uint8_t protocol)
|
||||
case PROTOCOL_CHANNELS_DSM2_LP45:
|
||||
case PROTOCOL_CHANNELS_DSM2_DSM2:
|
||||
case PROTOCOL_CHANNELS_DSM2_DSMX:
|
||||
#if defined(PCBSKY9X)
|
||||
extmoduleSerialStart(DSM2_BAUDRATE, DSM2_PERIOD * 2000, false);
|
||||
#else
|
||||
extmoduleSerialStart();
|
||||
mixerSchedulerSetPeriod(EXTERNAL_MODULE, DSM2_PERIOD);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -333,12 +329,8 @@ void enablePulsesExternalModule(uint8_t protocol)
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTOCOL_CHANNELS_MULTIMODULE:
|
||||
#if defined(PCBSKY9X)
|
||||
extmoduleSerialStart(MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000, true);
|
||||
#else
|
||||
extmoduleSerialStart();
|
||||
mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD);
|
||||
#endif
|
||||
getMultiModuleStatus(EXTERNAL_MODULE).failsafeChecked = false;
|
||||
getMultiModuleStatus(EXTERNAL_MODULE).flags = 0;
|
||||
#if defined(MULTI_PROTOLIST)
|
||||
@@ -349,12 +341,8 @@ void enablePulsesExternalModule(uint8_t protocol)
|
||||
|
||||
#if defined(SBUS)
|
||||
case PROTOCOL_CHANNELS_SBUS:
|
||||
#if defined(PCBSKY9X)
|
||||
extmoduleSerialStart(SBUS_BAUDRATE, SBUS_PERIOD_HALF_US, false);
|
||||
#else
|
||||
extmoduleSerialStart();
|
||||
mixerSchedulerSetPeriod(EXTERNAL_MODULE, SBUS_PERIOD);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,10 +33,6 @@
|
||||
#include "modules_helpers.h"
|
||||
#include "ff.h"
|
||||
|
||||
#if defined(PCBSKY9X) && defined(DSM2)
|
||||
#define DSM2_BIND_TIMEOUT 255 // 255*11ms
|
||||
extern uint8_t dsm2BindTimer;
|
||||
#endif
|
||||
|
||||
#if defined(DSM2)
|
||||
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTOCOL_CHANNELS_DSM2_LP45 && protocol<=PROTOCOL_CHANNELS_DSM2_DSMX)
|
||||
|
||||
@@ -170,8 +170,6 @@ const char * getBasename(const char * path);
|
||||
#define ETX_FOURCC 0x3378746F // etx for Taranis X9D
|
||||
#elif defined(PCBNV14)
|
||||
#define ETX_FOURCC 0x3A78746F // etx for NV14
|
||||
#elif defined(PCBSKY9X)
|
||||
#define ETX_FOURCC 0x3278746F // etx for sky9x
|
||||
#endif
|
||||
|
||||
bool isFileAvailable(const char * filename, bool exclDir = false);
|
||||
|
||||
@@ -431,15 +431,6 @@ void OpenTxSim::updateKeysAndSwitches(bool start)
|
||||
} \
|
||||
simuSetSwitch(swtch, state_##swtch) \
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
SWITCH_KEY(1, 0, 3);
|
||||
SWITCH_KEY(2, 1, 2);
|
||||
SWITCH_KEY(3, 2, 2);
|
||||
SWITCH_KEY(4, 3, 2);
|
||||
SWITCH_KEY(5, 4, 2);
|
||||
SWITCH_KEY(6, 5, 2);
|
||||
SWITCH_KEY(7, 6, 2);
|
||||
#else
|
||||
SWITCH_KEY(A, 0, 3);
|
||||
SWITCH_KEY(B, 1, 3);
|
||||
SWITCH_KEY(C, 2, 3);
|
||||
@@ -474,7 +465,6 @@ void OpenTxSim::updateKeysAndSwitches(bool start)
|
||||
SWITCH_KEY(Q, 16, 3);
|
||||
SWITCH_KEY(R, 17, 3);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
long OpenTxSim::onTimeout(FXObject*, FXSelector, void*)
|
||||
|
||||
@@ -53,10 +53,6 @@ enum Mix216Sources {
|
||||
MIXSRC216_LAST_POT = MIXSRC216_P3,
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
MIXSRC216_REa,
|
||||
MIXSRC216_LAST_ROTARY_ENCODER = MIXSRC216_REa,
|
||||
#endif
|
||||
|
||||
MIXSRC216_MAX,
|
||||
|
||||
@@ -527,13 +523,6 @@ PACK(typedef struct {
|
||||
uint8_t nPotsToWarn; \
|
||||
int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]; \
|
||||
uint8_t spare[2];
|
||||
#elif defined(PCBSKY9X)
|
||||
#define MODELDATA_EXTRA_216 \
|
||||
uint8_t externalModule; \
|
||||
ModuleData_v216 moduleData[NUM_MODULES+1]; \
|
||||
uint8_t nPotsToWarn; \
|
||||
int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]; \
|
||||
uint8_t rxBattAlarms[2];
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
@@ -882,15 +871,6 @@ void convertRadioData_217_to_218(RadioData &settings)
|
||||
memcpy(settings.bluetoothName, settings_v217.bluetoothName, sizeof(settings.bluetoothName));
|
||||
#endif
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
settings.txCurrentCalibration = settings_v217.txCurrentCalibration;
|
||||
settings.mAhWarn = settings_v217.mAhWarn;
|
||||
settings.mAhUsed = settings_v217.mAhUsed;
|
||||
settings.temperatureCalib = settings_v217.temperatureCalib;
|
||||
settings.optrexDisplay = settings_v217.optrexDisplay;
|
||||
settings.sticksGain = settings_v217.sticksGain;
|
||||
settings.rotarySteps = settings_v217.rotarySteps;
|
||||
#endif
|
||||
}
|
||||
|
||||
void convertModelData_216_to_217(ModelData &model)
|
||||
@@ -1206,9 +1186,6 @@ void convertModelData_217_to_218(ModelData &model)
|
||||
newModel.flightModeData[i].swtch = convertSwitch_217_to_218(oldModel.flightModeData[i].swtch);
|
||||
newModel.flightModeData[i].fadeIn = oldModel.flightModeData[i].fadeIn;
|
||||
newModel.flightModeData[i].fadeOut = oldModel.flightModeData[i].fadeOut;
|
||||
#if defined(PCBSKY9X)
|
||||
memcpy(newModel.flightModeData[i].rotaryEncoders, oldModel.flightModeData[i].rotaryEncoders, sizeof(newModel.flightModeData[i].rotaryEncoders));
|
||||
#endif
|
||||
memcpy(newModel.flightModeData[i].gvars, oldModel.flightModeData[i].gvars, sizeof(newModel.flightModeData[i].gvars));
|
||||
}
|
||||
newModel.thrTraceSrc = oldModel.thrTraceSrc;
|
||||
|
||||
@@ -110,12 +110,8 @@ void convertModelData_218_to_219(ModelData &model)
|
||||
{
|
||||
static_assert(sizeof(ModelData_v218) <= sizeof(ModelData), "ModelData size has been reduced");
|
||||
|
||||
#if defined(STM32)
|
||||
ModelData_v218 * oldModelAllocated = (ModelData_v218 *)malloc(sizeof(ModelData_v218));
|
||||
ModelData_v218 &oldModel = *oldModelAllocated;
|
||||
#else
|
||||
ModelData_v218 oldModel;
|
||||
#endif
|
||||
|
||||
memcpy(&oldModel, &model, sizeof(ModelData_v218));
|
||||
ModelData_v219 & newModel = (ModelData_v219 &) model;
|
||||
@@ -269,9 +265,7 @@ void convertModelData_218_to_219(ModelData &model)
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
newModel.trainerData.mode = oldModel.trainerMode;
|
||||
#endif
|
||||
newModel.trainerData.channelsStart = oldModel.moduleData[NUM_MODULES].channelsStart;
|
||||
newModel.trainerData.channelsCount = oldModel.moduleData[NUM_MODULES].channelsCount;
|
||||
newModel.trainerData.frameLength = oldModel.moduleData[NUM_MODULES].ppm.frameLength;
|
||||
@@ -365,9 +359,7 @@ void convertModelData_218_to_219(ModelData &model)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(STM32)
|
||||
free(oldModelAllocated);
|
||||
#endif
|
||||
}
|
||||
|
||||
void convertRadioData_218_to_219(RadioData & settings)
|
||||
@@ -377,11 +369,9 @@ void convertRadioData_218_to_219(RadioData & settings)
|
||||
settings.version = 219;
|
||||
settings.variant = EEPROM_VARIANT;
|
||||
|
||||
#if defined(STM32)
|
||||
RadioData_v218 * oldSettingsAllocated = (RadioData_v218 *)malloc(sizeof(RadioData_v218));
|
||||
RadioData_v218 & oldSettings = *oldSettingsAllocated;
|
||||
memcpy(&oldSettings, &settings, sizeof(RadioData_v218));
|
||||
#endif
|
||||
|
||||
#if defined(PCBX9D) || defined(PCBX9DP)
|
||||
// no bluetooth before PCBREV 2019
|
||||
@@ -451,7 +441,5 @@ void convertRadioData_218_to_219(RadioData & settings)
|
||||
settings.pwrOnSpeed = 0;
|
||||
settings.pwrOffSpeed = 0;
|
||||
|
||||
#if defined(STM32)
|
||||
free(oldSettingsAllocated);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -112,17 +112,6 @@
|
||||
#define MAX_INPUTS_218 32
|
||||
#define MAX_TRAINER_CHANNELS_218 16
|
||||
#define MAX_TELEMETRY_SENSORS_218 32
|
||||
#elif defined(PCBSKY9X)
|
||||
#define MAX_MODELS_218 60
|
||||
#define MAX_OUTPUT_CHANNELS_218 32 // number of real output channels CH1-CH32
|
||||
#define MAX_FLIGHT_MODES_218 9
|
||||
#define MAX_MIXERS_218 64
|
||||
#define MAX_EXPOS_218 32
|
||||
#define MAX_LOGICAL_SWITCHES_218 64
|
||||
#define MAX_SPECIAL_FUNCTIONS_218 64 // number of functions assigned to switches
|
||||
#define MAX_INPUTS_218 32
|
||||
#define MAX_TRAINER_CHANNELS_218 16
|
||||
#define MAX_TELEMETRY_SENSORS_218 32
|
||||
#endif
|
||||
|
||||
#if defined(COLORLCD)
|
||||
@@ -194,11 +183,7 @@ PACK(typedef struct {
|
||||
char name[LEN_TIMER_NAME_218];
|
||||
}) TimerData_v218;
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define ROTENC_DATA int16_t rotaryEncoders[1];
|
||||
#else
|
||||
#define ROTENC_DATA
|
||||
#endif
|
||||
|
||||
PACK(typedef struct {
|
||||
trim_t trim[NUM_TRIMS];
|
||||
@@ -343,8 +328,6 @@ PACK(struct FrSkyTelemetryData_v217 {
|
||||
#define MODELDATA_EXTRA_218 uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS_218]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[3 + 4];
|
||||
#elif defined(PCBTARANIS)
|
||||
#define MODELDATA_EXTRA_218 uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS_218]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS];
|
||||
#elif defined(PCBSKY9X)
|
||||
#define MODELDATA_EXTRA_218 uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS]; uint8_t rxBattAlarms[2];
|
||||
#endif
|
||||
|
||||
PACK(struct TelemetrySensor_218 {
|
||||
@@ -507,18 +490,6 @@ PACK(struct ModelData_v218 {
|
||||
char switchNames[NUM_SWITCHES_218][LEN_SWITCH_NAME_218]; \
|
||||
char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME_218]; \
|
||||
BLUETOOTH_FIELDS_218
|
||||
#elif defined(PCBSKY9X)
|
||||
#define EXTRA_GENERAL_FIELDS_218 \
|
||||
int8_t txCurrentCalibration; \
|
||||
int8_t temperatureWarn; \
|
||||
uint8_t mAhWarn; \
|
||||
uint16_t mAhUsed; \
|
||||
int8_t temperatureCalib; \
|
||||
uint8_t optrexDisplay; \
|
||||
uint8_t sticksGain; \
|
||||
uint8_t rotarySteps; \
|
||||
char switchNames[NUM_SWITCHES_218][LEN_SWITCH_NAME_218]; \
|
||||
char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME_218];
|
||||
#else
|
||||
#define EXTRA_GENERAL_FIELDS_218 EXTRA_GENERAL_FIELDS_GENERAL_218
|
||||
#endif
|
||||
|
||||
@@ -249,11 +249,7 @@ enum SwashType {
|
||||
|
||||
#define IS_MANUAL_RESET_TIMER(idx) (g_model.timers[idx].persistent == 2)
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
#define TIMER_COUNTDOWN_START(x) (g_model.timers[x].countdownStart == 0 ? 20 : (g_model.timers[x].countdownStart == 1 ? 30 : (g_model.timers[x].countdownStart == -1 ? 10 : 5)))
|
||||
#else
|
||||
#define TIMER_COUNTDOWN_START(x) 10
|
||||
#endif
|
||||
|
||||
// #include "pulses/modules_constants.h"
|
||||
|
||||
|
||||
@@ -263,14 +263,7 @@ bool eeLoadGeneral(bool allowFixes)
|
||||
|
||||
if (g_eeGeneral.version != EEPROM_VER) {
|
||||
TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER);
|
||||
#if defined(PCBSKY9X)
|
||||
if (!allowFixes)
|
||||
return false; // prevent eeprom from being wiped
|
||||
if (!eeConvert())
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -302,10 +295,8 @@ void storageFormat()
|
||||
void eepromWriteWait(EepromWriteState state/* = EEPROM_IDLE*/)
|
||||
{
|
||||
while (eepromWriteState != state) {
|
||||
#if defined(STM32)
|
||||
// Waits a little bit for CS transitions
|
||||
RTOS_WAIT_MS(2);
|
||||
#endif
|
||||
eepromWriteProcess();
|
||||
#ifdef SIMU
|
||||
sleep(5/*ms*/);
|
||||
@@ -466,10 +457,6 @@ const char * eeBackupModel(uint8_t i_fileSrc)
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
strcpy(statusLineMsg, "File ");
|
||||
strcpy(statusLineMsg+5, &buf[sizeof(MODELS_PATH)]);
|
||||
#endif
|
||||
|
||||
uint16_t size = eeModelSize(i_fileSrc);
|
||||
|
||||
@@ -499,9 +486,6 @@ const char * eeBackupModel(uint8_t i_fileSrc)
|
||||
|
||||
f_close(&archiveFile);
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
showStatusLine();
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#define WRITE_DELAY_10MS 1500 /* 15s */
|
||||
#elif defined(PCBTARANIS)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#elif defined(PCBSKY9X) && !defined(REV0)
|
||||
#define WRITE_DELAY_10MS 500
|
||||
#else
|
||||
#define WRITE_DELAY_10MS 200
|
||||
#endif
|
||||
|
||||
@@ -420,7 +420,6 @@ char *getFlightModeString(char *dest, int8_t idx)
|
||||
// return dest;
|
||||
// }
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
int getRawSwitchIdx(char sw)
|
||||
{
|
||||
if (sw < 'A' || sw > 'Z')
|
||||
@@ -484,7 +483,6 @@ char *getSwitchName(char *dest, swsrc_t idx)
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *getSwitchPositionName(char *dest, swsrc_t idx)
|
||||
{
|
||||
@@ -500,14 +498,6 @@ char *getSwitchPositionName(char *dest, swsrc_t idx)
|
||||
idx = -idx;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define IDX_TRIMS_IN_STR_VSWITCHES (1 + SWSRC_LAST_SWITCH)
|
||||
#define IDX_ON_IN_STR_VSWITCHES \
|
||||
(IDX_TRIMS_IN_STR_VSWITCHES + SWSRC_LAST_TRIM - SWSRC_FIRST_TRIM + 2)
|
||||
if (idx <= SWSRC_LAST_SWITCH) {
|
||||
getStringAtIndex(s, STR_VSWITCHES, idx);
|
||||
}
|
||||
#else
|
||||
#define IDX_TRIMS_IN_STR_VSWITCHES (1)
|
||||
#define IDX_ON_IN_STR_VSWITCHES \
|
||||
(IDX_TRIMS_IN_STR_VSWITCHES + SWSRC_LAST_TRIM - SWSRC_FIRST_TRIM + 1)
|
||||
@@ -517,7 +507,6 @@ char *getSwitchPositionName(char *dest, swsrc_t idx)
|
||||
*s++ = (STR_CHAR_UP "-" STR_CHAR_DOWN)[swinfo.rem];
|
||||
*s = '\0';
|
||||
}
|
||||
#endif // PCBSKY9X
|
||||
|
||||
#if NUM_XPOTS > 0
|
||||
else if (idx <= SWSRC_LAST_MULTIPOS_SWITCH) {
|
||||
|
||||
@@ -78,9 +78,7 @@ if(Qt5Widgets_FOUND)
|
||||
set(all_libs_cmd ${CMAKE_COMMAND} -E echo "Building all simulator libraries")
|
||||
foreach(pcb ${PCB_TYPES})
|
||||
set(pcbrev "")
|
||||
if(pcb STREQUAL SKY9X)
|
||||
set(pcbrev "-DPCBREV=REVC")
|
||||
elseif(pcb STREQUAL X12S)
|
||||
if(pcb STREQUAL X12S)
|
||||
set(pcbrev "-DPCBREV=13")
|
||||
endif()
|
||||
set(all_libs_cmd ${all_libs_cmd} && ${CMAKE_COMMAND} -DPCB=${pcb} ${pcbrev} -Wno-dev ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} && ${CMAKE_COMMAND} --build . --target libsimulator -- ${mkflags})
|
||||
|
||||
@@ -633,7 +633,7 @@ const int OpenTxSimulator::voltageToAdc(const int volts)
|
||||
int ret = 0;
|
||||
#if defined(PCBHORUS) || defined(PCBX7)
|
||||
ret = (float)volts * 16.2f;
|
||||
#elif defined(PCBTARANIS) || defined(PCBSKY9X)
|
||||
#elif defined(PCBTARANIS)
|
||||
ret = (float)volts * 13.3f;
|
||||
#else
|
||||
ret = (float)volts * 14.15f;
|
||||
|
||||
@@ -47,7 +47,6 @@ bool simu_running = false;
|
||||
|
||||
uint32_t telemetryErrors = 0;
|
||||
|
||||
#if defined(STM32)
|
||||
GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
|
||||
TIM_TypeDef tim1, tim2, tim3, tim4, tim5, tim6, tim7, tim8, tim9, tim10;
|
||||
RCC_TypeDef rcc;
|
||||
@@ -76,17 +75,6 @@ void DMA_ClearITPendingBit(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_IT) {
|
||||
void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState) { }
|
||||
void UART3_Configure(uint32_t baudrate, uint32_t masterClock) { }
|
||||
void NVIC_Init(NVIC_InitTypeDef * NVIC_InitStruct) { }
|
||||
#else
|
||||
Pio Pioa, Piob, Pioc;
|
||||
Pmc pmc;
|
||||
Ssc ssc;
|
||||
Pwm pwm;
|
||||
Tc tc1;
|
||||
Twi Twio;
|
||||
Usart Usart0;
|
||||
Dacc dacc;
|
||||
Adc Adc0;
|
||||
#endif
|
||||
|
||||
FATFS g_FATFS_Obj;
|
||||
|
||||
@@ -141,9 +129,7 @@ uint64_t CoGetOSTime(void)
|
||||
|
||||
void simuInit()
|
||||
{
|
||||
#if defined(STM32)
|
||||
RCC->CSR = 0;
|
||||
#endif
|
||||
|
||||
// set power button to "not pressed"
|
||||
#if defined(PWR_SWITCH_GPIO) // STM32
|
||||
@@ -610,18 +596,6 @@ uint32_t readTrims()
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
#if defined(PCBSKY9X)
|
||||
switch(index) {
|
||||
case 0:
|
||||
return switchesStates[0] < 0;
|
||||
case 1:
|
||||
return switchesStates[0] == 0;
|
||||
case 2:
|
||||
return switchesStates[0] > 0;
|
||||
default:
|
||||
return switchesStates[index - 2] > 0;
|
||||
}
|
||||
#else
|
||||
div_t qr = div(index, 3);
|
||||
int state = switchesStates[qr.quot];
|
||||
switch (qr.rem) {
|
||||
@@ -632,10 +606,8 @@ uint32_t switchState(uint8_t index)
|
||||
default:
|
||||
return state == 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(STM32)
|
||||
int usbPlugged() { return false; }
|
||||
int getSelectedUsbMode() { return USB_JOYSTICK_MODE; }
|
||||
void setSelectedUsbMode(int mode) {}
|
||||
@@ -747,7 +719,6 @@ uint32_t isBootloaderStart(const uint8_t * block)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif // defined(STM32)
|
||||
|
||||
#if defined(PCBXLITES)
|
||||
bool isJackPlugged()
|
||||
|
||||
@@ -83,7 +83,6 @@ void sig(int sgn)
|
||||
|
||||
#define __REV
|
||||
|
||||
#if defined(STM32)
|
||||
extern GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
|
||||
extern TIM_TypeDef tim1, tim2, tim3, tim4, tim5, tim6, tim7, tim8, tim9, tim10;
|
||||
extern USART_TypeDef Usart0, Usart1, Usart2, Usart3, Usart4;
|
||||
@@ -175,48 +174,6 @@ extern RTC_TypeDef rtc;
|
||||
#define ADC (&adc)
|
||||
#undef RTC
|
||||
#define RTC (&rtc)
|
||||
#elif defined(PCBSKY9X)
|
||||
extern Pmc pmc;
|
||||
#undef PMC
|
||||
#define PMC (&pmc)
|
||||
extern Ssc ssc;
|
||||
#undef SSC
|
||||
#define SSC (&ssc)
|
||||
extern Pmc pmc;
|
||||
#undef PMC
|
||||
#define PMC (&pmc)
|
||||
extern Tc tc1;
|
||||
#undef TC1
|
||||
#define TC1 (&tc1)
|
||||
extern Pio Pioa, Piob, Pioc;
|
||||
extern Twi Twio;
|
||||
extern Dacc dacc;
|
||||
extern Usart Usart0;
|
||||
extern Adc Adc0;
|
||||
#undef ADC
|
||||
#define ADC (&Adc0)
|
||||
#undef USART0
|
||||
#define USART0 (&Usart0)
|
||||
#undef USART1
|
||||
#define USART1 (&Usart0)
|
||||
#undef USART2
|
||||
#define USART2 (&Usart0)
|
||||
#undef USART3
|
||||
#define USART3 (&Usart0)
|
||||
#undef PIOA
|
||||
#define PIOA (&Pioa)
|
||||
#undef PIOB
|
||||
#define PIOB (&Piob)
|
||||
#undef PIOC
|
||||
#define PIOC (&Pioc)
|
||||
#undef TWI0
|
||||
#define TWI0 (&Twio)
|
||||
#undef DACC
|
||||
#define DACC (&dacc)
|
||||
extern Pwm pwm;
|
||||
#undef PWM
|
||||
#define PWM (&pwm)
|
||||
#endif
|
||||
|
||||
extern uint8_t * eeprom;
|
||||
extern void startPdcUsartReceive() ;
|
||||
@@ -276,7 +233,6 @@ void simuMain();
|
||||
#define USART_GetITStatus(...) 0
|
||||
#define USART_ClearFlag(...)
|
||||
|
||||
#if defined(STM32)
|
||||
#define TIM_DeInit(...)
|
||||
#define TIM_SetCompare2(...)
|
||||
#define TIM_ClearFlag(...)
|
||||
@@ -287,7 +243,6 @@ void simuMain();
|
||||
#define GPIO_ReadInputDataBit(GPIOx, pin) (GPIOx->BSRRL & pin)
|
||||
#define RCC_AHB1PeriphClockCmd(...)
|
||||
#define RCC_APB2PeriphClockCmd(...)
|
||||
#endif
|
||||
|
||||
// inline void delay_01us(uint32_t dummy) { }
|
||||
|
||||
|
||||
@@ -609,9 +609,5 @@ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs)
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
int32_t Card_state = SD_ST_MOUNTED;
|
||||
uint32_t Card_CSD[4]; // TODO elsewhere
|
||||
#endif
|
||||
|
||||
#endif // #if defined(SIMU_USE_SDCARD)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,151 +0,0 @@
|
||||
set(ARCH ARM)
|
||||
set(LUA NO)
|
||||
set(MCU cortex-m3)
|
||||
set(SDCARD YES)
|
||||
set(HAPTIC YES)
|
||||
set(STORAGE EEPROM)
|
||||
set(STORAGE_FORMAT RAW)
|
||||
set(GUI_DIR 128x64)
|
||||
set(BITMAPS_DIR 128x64)
|
||||
set(NAVIGATION_TYPE 9x)
|
||||
set(BITMAPS_TARGET 9x_bitmaps)
|
||||
set(TARGET_DIR sky9x)
|
||||
set(RADIO_DEPENDENCIES ${RADIO_DEPENDENCIES} 9x_bitmaps)
|
||||
set(PPM_LIMITS_SYMETRICAL YES)
|
||||
set(PXX1 YES)
|
||||
set(AFHDS3 NO)
|
||||
set(GHOST NO)
|
||||
add_definitions(-DHARDWARE_EXTERNAL_MODULE)
|
||||
add_definitions(-DDISABLE_MULTI_UPDATE)
|
||||
|
||||
if(PCB STREQUAL 9XRPRO)
|
||||
add_definitions(-Dat91sam3s8 -DREVX)
|
||||
set(FLAVOUR 9xrpro)
|
||||
set(LINKER_SCRIPT targets/sky9x/sam3s8c_flash.ld)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
rtc_driver.cpp
|
||||
)
|
||||
set(OPENRC_BOOTLOADER bootflash8.lbm)
|
||||
set(CPU_TYPE_FULL ATSAM3S8C) # for size report
|
||||
elseif(PCB STREQUAL AR9X)
|
||||
add_definitions(-Dat91sam3s8 -DPCBAR9X -DSOFTWARE_VOLUME)
|
||||
set(FLAVOUR ar9x)
|
||||
include_directories(${THIRDPARTY_DIR}/xdk-asf-3.31.0/sam/drivers/twi)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../../${THIRDPARTY_DIR}/xdk-asf-3.31.0/sam/drivers/twi/twi.c
|
||||
i2c_driver.cpp
|
||||
rtc_ds3231_driver.cpp
|
||||
)
|
||||
set(LINKER_SCRIPT targets/sky9x/sam3s8c_flash.ld)
|
||||
set(OPENRC_BOOTLOADER bootflash8.lbm)
|
||||
set(CPU_TYPE_FULL ATSAM3S8C) # for size report
|
||||
else()
|
||||
set(FLAVOUR sky9x)
|
||||
set(PCBREV "REVC" CACHE STRING "PCB Revision (REVB/REVC)")
|
||||
set_property(CACHE PCBREV PROPERTY STRINGS "REVB" "REVC")
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
coproc_driver.cpp
|
||||
rotary_encoder_driver.cpp
|
||||
rtc_driver.cpp
|
||||
)
|
||||
set(OPENRC_BOOTLOADER bootflash4.lbm)
|
||||
if(PCBREV STREQUAL REVB)
|
||||
add_definitions(-DDREVB)
|
||||
elseif(PCBREV STREQUAL REVC)
|
||||
add_definitions(-DDREVC)
|
||||
else()
|
||||
message(SEND_ERROR "Unknown PCB Revision '${PCBREV}'")
|
||||
endif()
|
||||
add_definitions(-DCOPROCESSOR)
|
||||
set(LINKER_SCRIPT targets/sky9x/sam3s4c_flash.ld)
|
||||
set(CPU_TYPE_FULL ATSAM3S4C) # for size report
|
||||
endif()
|
||||
|
||||
add_definitions(-DPCBSKY9X -DPPM_PIN_SERIAL -DAUDIO_DUAL_BUFFER)
|
||||
add_definitions(-DAUDIO -DVOICE -DRTCLOCK -DVARIO)
|
||||
add_definitions(-DEEPROM_VARIANT=0)
|
||||
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
model_input_edit.cpp
|
||||
model_mix_edit.cpp
|
||||
model_display.cpp
|
||||
radio_diagkeys.cpp
|
||||
radio_diaganas.cpp
|
||||
view_telemetry.cpp
|
||||
view_about.cpp
|
||||
view_channels.cpp
|
||||
)
|
||||
|
||||
if(GVARS)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
model_gvars.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/loadboot.cpp
|
||||
board.cpp
|
||||
core_cm3.c
|
||||
board_lowlevel.c
|
||||
crt.c
|
||||
vectors_sam3s.c
|
||||
eeprom_driver.cpp
|
||||
lcd_driver.cpp
|
||||
pwr_driver.cpp
|
||||
joystick.cpp
|
||||
massstorage.cpp
|
||||
keys_driver.cpp
|
||||
usb/device/core/USBD_UDP.c
|
||||
usb/device/core/USBDDriver.c
|
||||
usb_driver.cpp
|
||||
usb/device/massstorage/MSDDriver.c
|
||||
usb/device/massstorage/MSDDStateMachine.c
|
||||
usb/device/massstorage/MSDLun.c
|
||||
usb/device/massstorage/MSDDriverDescriptors.c
|
||||
usb/device/massstorage/SBCMethods.c
|
||||
usb/device/hid-joystick/HIDDJoystickDriver.c
|
||||
usb/device/hid-joystick/HIDDJoystickDriverDescriptors.c
|
||||
usb/device/hid-joystick/HIDDJoystickInputReport.c
|
||||
usb/common/core/USBEndpointDescriptor.c
|
||||
usb/common/core/USBGenericRequest.c
|
||||
usb/common/core/USBFeatureRequest.c
|
||||
usb/common/core/USBInterfaceRequest.c
|
||||
usb/common/core/USBGetDescriptorRequest.c
|
||||
usb/common/core/USBSetAddressRequest.c
|
||||
usb/common/core/USBSetConfigurationRequest.c
|
||||
usb/common/core/USBConfigurationDescriptor.c
|
||||
usb/common/core/USBGenericDescriptor.c
|
||||
usb/common/hid/HIDIdleRequest.c
|
||||
usb/common/hid/HIDReportRequest.c
|
||||
MEDSdcard.c
|
||||
)
|
||||
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
telemetry_driver.cpp
|
||||
)
|
||||
|
||||
set(TARGET_SRC
|
||||
${TARGET_SRC}
|
||||
adc_driver.cpp
|
||||
pulses_driver.cpp
|
||||
audio_driver.cpp
|
||||
buzzer_driver.cpp
|
||||
haptic_driver.cpp
|
||||
sdcard_driver.cpp
|
||||
aux_serial_driver.cpp
|
||||
audio_driver.cpp
|
||||
trainer_driver.cpp
|
||||
)
|
||||
|
||||
set(SRC
|
||||
${SRC}
|
||||
debug.cpp
|
||||
)
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
#include "diskio.h"
|
||||
#include "board_lowlevel.h"
|
||||
#include "Media.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Constants
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Number of SD Slots
|
||||
#define NUM_SD_SLOTS 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Checks if the device is write protected.
|
||||
/// \return 1 if protected.
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static unsigned char CardIsProtected(unsigned char slot)
|
||||
{
|
||||
if (slot == 0) {
|
||||
#ifdef BOARD_SD_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (slot == 1) {
|
||||
#ifdef BOARD_SD_MCI1_PIN_WP
|
||||
PIO_Configure(&pinMciWriteProtect1, 1);
|
||||
return (PIO_Get(&pinMciWriteProtect1) != 0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Configure the PIO for SD
|
||||
//------------------------------------------------------------------------------
|
||||
#if 0
|
||||
static void ConfigurePIO(unsigned char mciID)
|
||||
{
|
||||
#ifdef BOARD_SD_PINS
|
||||
const Pin pinSd0[] = {BOARD_SD_PINS};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
const Pin pinSd1[] = {BOARD_SD_MCI1_PINS};
|
||||
#endif
|
||||
|
||||
if(mciID == 0) {
|
||||
#ifdef BOARD_SD_PINS
|
||||
PIO_Configure(pinSd0, PIO_LISTSIZE(pinSd0));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef BOARD_SD_MCI1_PINS
|
||||
PIO_Configure(pinSd1, PIO_LISTSIZE(pinSd1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a SDCARD memory
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
TRACE_DEBUG("MEDSdcard_Read(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media is ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_INFO("Media busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to read is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Read: Data too big: %d, %d\n\r",
|
||||
(int)length, (int)address);
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Enter Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_read (0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke callback
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a SDRAM media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see Media
|
||||
//! \see MediaCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static unsigned char MEDSdcard_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
|
||||
TRACE_DEBUG("MEDSdcard_Write(address=%d length=%d)\n\r", address, length);
|
||||
|
||||
// Check that the media if ready
|
||||
if (media->state != MED_STATE_READY) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Media is busy\n\r");
|
||||
return MED_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Check that the data to write is not too big
|
||||
if ((length + address) > media->size) {
|
||||
|
||||
TRACE_WARNING("MEDSdcard_Write: Data too big\n\r");
|
||||
return MED_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Put the media in Busy state
|
||||
media->state = MED_STATE_BUSY;
|
||||
|
||||
disk_write(0, data, address, length);
|
||||
|
||||
// Leave the Busy state
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
// Invoke the callback if it exists
|
||||
if (callback != 0) {
|
||||
|
||||
callback(argument, MED_STATUS_SUCCESS, 0, 0);
|
||||
}
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Initializes a Media instance and the associated physical interface
|
||||
/// \param media Pointer to the Media instance to initialize
|
||||
/// \return 1 if success.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID)
|
||||
{
|
||||
TRACE_INFO("MEDSdcard init\n\r");
|
||||
|
||||
// Initialize SDcard
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
if ( !SD_CARD_PRESENT( ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
media->write = MEDSdcard_Write;
|
||||
media->read = MEDSdcard_Read;
|
||||
media->lock = 0;
|
||||
media->unlock = 0;
|
||||
media->handler = 0;
|
||||
media->flush = 0;
|
||||
|
||||
media->blockSize = BLOCK_SIZE;
|
||||
media->baseAddress = 0;
|
||||
|
||||
media->size = SD_GET_BLOCKNR();
|
||||
|
||||
media->mappedRD = 0;
|
||||
media->mappedWR = 0;
|
||||
media->protected = 0;
|
||||
media->removable = 1;
|
||||
|
||||
media->state = MED_STATE_READY;
|
||||
|
||||
media->transfer.data = 0;
|
||||
media->transfer.address = 0;
|
||||
media->transfer.length = 0;
|
||||
media->transfer.callback = 0;
|
||||
media->transfer.argument = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,280 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Generic Media type, which provides transparent access to all types of
|
||||
/// memories.
|
||||
///
|
||||
/// \note The physical or HW related media operations (physical device
|
||||
/// connection & protection detecting, PIO configurations and interface
|
||||
/// driver initialization) are excluded.
|
||||
///
|
||||
/// !Usage
|
||||
/// -# Do PIO initialization for peripheral interfaces.
|
||||
/// -# Initialize peripheral interface driver & device driver.
|
||||
/// -# Initialize specific media interface and link to this initialized driver.
|
||||
///
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MEDIA_H_
|
||||
#define _MEDIA_H_
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//! \brief Operation result code returned by media methods
|
||||
#define MED_STATUS_SUCCESS 0x00
|
||||
#define MED_STATUS_ERROR 0x01
|
||||
#define MED_STATUS_BUSY 0x02
|
||||
#define MED_STATUS_PROTECTED 0x04
|
||||
|
||||
//! \brief Media statuses
|
||||
#define MED_STATE_READY 0x00 /// Media is ready for access
|
||||
#define MED_STATE_BUSY 0x01 /// Media is busy
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct _Media Media;
|
||||
|
||||
typedef void (*MediaCallback)(void *argument,
|
||||
unsigned char status,
|
||||
unsigned int transferred,
|
||||
unsigned int remaining);
|
||||
|
||||
typedef unsigned char (*Media_write)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_read)(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument);
|
||||
|
||||
typedef unsigned char (*Media_cancelIo)(Media *media);
|
||||
|
||||
typedef unsigned char (*Media_lock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_unlock)(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd);
|
||||
|
||||
typedef unsigned char (*Media_ioctl)(Media *media,
|
||||
unsigned char ctrl,
|
||||
void *buff);
|
||||
|
||||
typedef unsigned char (*Media_flush)(Media *media);
|
||||
|
||||
typedef void (*Media_handler)(Media *media);
|
||||
|
||||
//! \brief Media transfer
|
||||
//! \see TransferCallback
|
||||
typedef struct {
|
||||
|
||||
void *data; //!< Pointer to the data buffer
|
||||
unsigned int address; //!< Address where to read/write the data
|
||||
unsigned int length; //!< Size of the data to read/write
|
||||
MediaCallback callback; //!< Callback to invoke when the transfer done
|
||||
void *argument; //!< Callback argument
|
||||
|
||||
} MEDTransfer;
|
||||
|
||||
//! \brief Media object
|
||||
//! \see MEDTransfer
|
||||
struct _Media {
|
||||
|
||||
Media_write write; //!< Write method
|
||||
Media_read read; //!< Read method
|
||||
Media_cancelIo cancelIo; //!< Cancel pending IO method
|
||||
Media_lock lock; //!< lock method if possible
|
||||
Media_unlock unlock; //!< unlock method if possible
|
||||
Media_flush flush; //!< Flush method
|
||||
Media_handler handler; //!< Interrupt handler
|
||||
unsigned int blockSize; //!< Block size in bytes (1, 512, 1K, 2K ...)
|
||||
unsigned int baseAddress; //!< Base address of media in number of blocks
|
||||
unsigned int size; //!< Size of media in number of blocks
|
||||
MEDTransfer transfer; //!< Current transfer operation
|
||||
void *interface; //!< Pointer to the physical interface used
|
||||
unsigned char bReserved:4,
|
||||
mappedRD:1, //!< Mapped to memory space to read
|
||||
mappedWR:1, //!< Mapped to memory space to write
|
||||
#ifdef __cplusplus
|
||||
protectd:1, //!< Protected media?
|
||||
#else
|
||||
protected:1, //!< Protected media?
|
||||
#endif
|
||||
removable:1; //!< Removable/Fixed media?
|
||||
unsigned char state; //!< Status of media
|
||||
unsigned short reserved;
|
||||
};
|
||||
|
||||
/// Available medias.
|
||||
extern Media medias[];
|
||||
|
||||
/// Number of medias which are effectively used.
|
||||
/// Defined by Media, shared usage by USB MSD & FS ...
|
||||
extern unsigned int numMedias;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Inline Functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Writes data on a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address at which to write
|
||||
//! \param data Pointer to the data to write
|
||||
//! \param length Size of the data buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the write operation terminates
|
||||
//! \param argument Optional argument for the callback function
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Write(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->write(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Reads a specified amount of data from a media
|
||||
//! \param media Pointer to a Media instance
|
||||
//! \param address Address of the data to read
|
||||
//! \param data Pointer to the buffer in which to store the retrieved
|
||||
//! data
|
||||
//! \param length Length of the buffer
|
||||
//! \param callback Optional pointer to a callback function to invoke when
|
||||
//! the operation is finished
|
||||
//! \param argument Optional pointer to an argument for the callback
|
||||
//! \return Operation result code
|
||||
//! \see TransferCallback
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Read(Media *media,
|
||||
unsigned int address,
|
||||
void *data,
|
||||
unsigned int length,
|
||||
MediaCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
return media->read(media, address, data, length, callback, argument);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Locks all the regions in the given address range.
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of lock range.
|
||||
/// \param end End address of lock range.
|
||||
/// \param pActualStart Start address of the actual lock range (optional).
|
||||
/// \param pActualEnd End address of the actual lock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Lock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->lock ) {
|
||||
return media->lock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Unlocks all the regions in the given address range
|
||||
//! \param media Pointer to a Media instance
|
||||
/// \param start Start address of unlock range.
|
||||
/// \param end End address of unlock range.
|
||||
/// \param pActualStart Start address of the actual unlock range (optional).
|
||||
/// \param pActualEnd End address of the actual unlock range (optional).
|
||||
/// \return 0 if successful; otherwise returns an error code.
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Unlock(Media *media,
|
||||
unsigned int start,
|
||||
unsigned int end,
|
||||
unsigned int *pActualStart,
|
||||
unsigned int *pActualEnd)
|
||||
{
|
||||
if( media->unlock ) {
|
||||
return media->unlock(media, start, end, pActualStart, pActualEnd);
|
||||
}
|
||||
else {
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline unsigned char MED_Flush(Media *media)
|
||||
{
|
||||
if (media->flush) {
|
||||
|
||||
return media->flush(media);
|
||||
}
|
||||
else {
|
||||
|
||||
return MED_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Invokes the interrupt handler of the specified media
|
||||
//! \param media Pointer to the Media instance to use
|
||||
//------------------------------------------------------------------------------
|
||||
static inline void MED_Handler(Media *media)
|
||||
{
|
||||
if (media->handler) {
|
||||
|
||||
media->handler(media);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void MED_HandleAll(Media *medias, unsigned char numMedias);
|
||||
|
||||
#endif // _MEDIA_H_
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint16_t adcValues[NUM_ANALOGS];
|
||||
|
||||
#if defined(FRSKY_STICKS)
|
||||
const char ana_direction[NUM_ANALOGS] = {1, 1, 0, 1 ,0 ,1 ,0, 0, 0};
|
||||
#endif
|
||||
|
||||
|
||||
// Settings for mode register ADC_MR
|
||||
// USEQ off - silicon problem, doesn't work
|
||||
// TRANSFER = 3
|
||||
// TRACKTIM = 15 (16 clock periods)
|
||||
// ANACH = 1
|
||||
// SETTLING = 6 (not used if ANACH = 0)
|
||||
// STARTUP = 6 (96 clock periods)
|
||||
// PRESCAL = 9.0 MHz clock (between 1 and 20MHz)
|
||||
// FREERUN = 0
|
||||
// FWUP = 0
|
||||
// SLEEP = 0
|
||||
// LOWRES = 0
|
||||
// TRGSEL = 0
|
||||
// TRGEN = 0 (software trigger only)
|
||||
void adcInit()
|
||||
{
|
||||
Adc *padc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = ( Master_frequency / (3600000*2) ) << 8 ;
|
||||
// Enable peripheral clock ADC = bit 29
|
||||
PMC->PMC_PCER0 |= 0x20000000L ; // Enable peripheral clock to ADC
|
||||
padc = ADC ;
|
||||
padc->ADC_MR = 0x3FB60000 | timer ; // 0011 1111 1011 0110 xxxx xxxx 0000 0000
|
||||
padc->ADC_ACR = ADC_ACR_TSON ; // Turn on temp sensor
|
||||
padc->ADC_CHER = 0x0000E33E ; // channels 1,2,3,4,5,8,9,13,14,15
|
||||
padc->ADC_CGR = 0 ; // Gain = 1, all channels
|
||||
padc->ADC_COR = 0 ; // Single ended, 0 offset, all channels
|
||||
}
|
||||
|
||||
// Read 8 (9 for REVB) ADC channels
|
||||
// Documented bug, must do them 1 by 1
|
||||
void adcSingleRead()
|
||||
{
|
||||
Adc *padc;
|
||||
uint32_t y;
|
||||
uint32_t x;
|
||||
|
||||
for (uint8_t i=0; i<4; i++)
|
||||
padc = ADC;
|
||||
y = padc->ADC_ISR; // Clear EOC flags
|
||||
for (y = NUM_ANALOGS+1; --y > 0;) {
|
||||
padc->ADC_CR = 2; // Start conversion
|
||||
x = 0;
|
||||
while ((padc->ADC_ISR & 0x01000000) == 0) {
|
||||
// wait for DRDY flag
|
||||
if (++x > 1000000) {
|
||||
break; // Software timeout
|
||||
}
|
||||
}
|
||||
x = padc->ADC_LCDR; // Clear DRSY flag
|
||||
}
|
||||
// Next bit may be done using the PDC
|
||||
adcValues[0] = ADC->ADC_CDR1;
|
||||
adcValues[1] = ADC->ADC_CDR2;
|
||||
adcValues[2] = ADC->ADC_CDR3;
|
||||
adcValues[3] = ADC->ADC_CDR4;
|
||||
adcValues[4] = ADC->ADC_CDR5;
|
||||
adcValues[5] = ADC->ADC_CDR9;
|
||||
adcValues[6] = ADC->ADC_CDR13;
|
||||
adcValues[7] = ADC->ADC_CDR14;
|
||||
adcValues[8] = ADC->ADC_CDR8 ;
|
||||
|
||||
// adc direction correct
|
||||
#if defined(FRSKY_STICKS)
|
||||
uint32_t i ;
|
||||
for (i=0; i<NUM_ANALOGS; i++) {
|
||||
if (ana_direction[i]) {
|
||||
adcValues[i] = 4096-adcValues[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
{
|
||||
uint16_t temp[NUM_ANALOGS] = { 0 };
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
adcSingleRead();
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
uint16_t val = adcValues[x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[x].measure(val);
|
||||
}
|
||||
#endif
|
||||
temp[x] += val;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x=0; x<NUM_ANALOGS; x++) {
|
||||
adcValues[x] = temp[x] >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(SIMU)
|
||||
uint16_t getAnalogValue(uint8_t index)
|
||||
{
|
||||
#if defined(PCBSKY9X)
|
||||
static const uint8_t mapping[] = {1,5,7,0,4,6,2,3};
|
||||
index = mapping[index];
|
||||
#endif
|
||||
return adcValues[index];
|
||||
}
|
||||
#endif // #if !defined(SIMU)
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t dacStarted = false;
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
const int8_t volumeScale[VOLUME_LEVEL_MAX+1] =
|
||||
{
|
||||
0, 2, 4, 6, 8, 10, 13, 17, 22, 27, 33, 40,
|
||||
64, 82, 96, 105, 112, 117, 120, 122, 124, 125, 126, 127
|
||||
} ;
|
||||
#endif
|
||||
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = Master_frequency / (8 * frequency) ; // MCK/8 and 100 000 Hz
|
||||
if (timer > 65535)
|
||||
timer = 65535 ;
|
||||
if (timer < 2)
|
||||
timer = 2 ;
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; // Stop clock
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
// Start TIMER1 at 100000Hz, used for DACC trigger
|
||||
void dacTimerStart()
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x01000000L ; // Enable peripheral clock to TC1
|
||||
|
||||
timer = Master_frequency / 800000 ; // MCK/8 and 100 000 Hz
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 0 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x00008000 ; // Waveform mode
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ; // 100 000 Hz
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x0009C001 ; // 0000 0000 0000 1001 1100 0000 0000 0001
|
||||
// MCK/8, set @ RA, Clear @ RC waveform
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
// Sound_g.Frequency = 1000 ;
|
||||
}
|
||||
|
||||
// Configure DAC0
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerStart() ;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
|
||||
Dacc *dacptr = DACC;
|
||||
|
||||
dacptr->DACC_MR = 0x0B000215L ; // 0000 1011 0000 0001 0000 0010 0001 0101
|
||||
dacptr->DACC_CHER = 1 ; // Enable channel 0
|
||||
dacptr->DACC_CDR = 2048 ; // Half amplitude
|
||||
dacptr->DACC_PTCR = DACC_PTCR_TXTEN ;
|
||||
|
||||
NVIC_EnableIRQ(DACC_IRQn) ;
|
||||
}
|
||||
|
||||
inline void dacStart()
|
||||
{
|
||||
PMC->PMC_PCER0 |= 0x40000000L ; // Enable peripheral clock to DAC
|
||||
DACC->DACC_IER = DACC_IER_ENDTX ;
|
||||
dacStarted = true;
|
||||
}
|
||||
|
||||
inline void dacStop()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ; // Disable interrupt
|
||||
dacStarted = false;
|
||||
}
|
||||
|
||||
void audioConsumeCurrentBuffer()
|
||||
{
|
||||
if (!dacStarted) {
|
||||
dacStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" void DAC_IRQHandler()
|
||||
{
|
||||
uint32_t sr = DACC->DACC_ISR;
|
||||
if (sr & DACC_ISR_ENDTX) {
|
||||
audioQueue.buffersFifo.freeNextFilledBuffer();
|
||||
const AudioBuffer * nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
// Try the first PDC buffer
|
||||
if ((DACC->DACC_TCR == 0) && (DACC->DACC_TNCR == 0)) {
|
||||
DACC->DACC_TPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
// Try the second PDC buffer
|
||||
if (DACC->DACC_TNCR == 0) {
|
||||
DACC->DACC_TNPR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
DACC->DACC_TNCR = nextBuffer->size/2;
|
||||
DACC->DACC_PTCR = DACC_PTCR_TXTEN;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dacStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sound routines
|
||||
void audioInit()
|
||||
{
|
||||
Pio * pioptr ;
|
||||
|
||||
dacInit() ;
|
||||
|
||||
pioptr = PIOA ;
|
||||
pioptr->PIO_CODR = 0x02000000L ; // Set bit A25 OFF
|
||||
pioptr->PIO_PER = 0x02000000L ; // Enable bit A25 (Stock buzzer)
|
||||
pioptr->PIO_OER = 0x02000000L ; // Set bit A25 as output
|
||||
|
||||
#if defined(REVX)
|
||||
configure_pins( PIO_PC26, PIN_ENABLE | PIN_LOW | PIN_OUTPUT | PIN_PORTC | PIN_NO_PULLUP ) ;
|
||||
PIOC->PIO_CODR = PIO_PC26 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void audioEnd()
|
||||
{
|
||||
DACC->DACC_IDR = DACC_IDR_ENDTX ;
|
||||
DACC->DACC_IDR = DACC_IDR_TXBUFE ;
|
||||
NVIC_DisableIRQ(DACC_IRQn) ;
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP ;
|
||||
NVIC_DisableIRQ(TWI0_IRQn) ;
|
||||
PMC->PMC_PCER0 &= ~0x00080000L ; // Disable peripheral clock to TWI0
|
||||
PMC->PMC_PCER0 &= ~0x40000000L ; // Disable peripheral clock to DAC
|
||||
}
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
void setScaledVolume(uint8_t volume)
|
||||
{
|
||||
volumeRequired = volumeScale[min<uint8_t>(volume, VOLUME_LEVEL_MAX)];
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_DRIVER_H_
|
||||
#define _AUDIO_DRIVER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
void audioInit() ;
|
||||
void audioEnd() ;
|
||||
void audioConsumeCurrentBuffer();
|
||||
#define audioDisableIrq() __disable_irq()
|
||||
#define audioEnableIrq() __enable_irq()
|
||||
|
||||
void setSampleRate( uint32_t frequency ) ;
|
||||
|
||||
#define VOLUME_LEVEL_MAX 23
|
||||
#define VOLUME_LEVEL_DEF 12
|
||||
|
||||
void setScaledVolume(uint8_t volume);
|
||||
|
||||
#define audioWaitReady()
|
||||
|
||||
#endif // _AUDIO_DRIVER_H_
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/** Usart Hw interface used by the console (UART0). */
|
||||
#define SECOND_SERIAL_UART UART0
|
||||
/** Usart Hw ID used by the console (UART0). */
|
||||
#define SECOND_SERIAL_ID ID_UART0
|
||||
/** Pins description corresponding to Rxd,Txd, (UART pins) */
|
||||
#define SECOND_SERIAL_PINS {PINS_UART}
|
||||
|
||||
Fifo<uint8_t, 512> auxSerialRxFifo;
|
||||
|
||||
#if !defined(SIMU)
|
||||
/*
|
||||
* Outputs a character on the UART line.
|
||||
*
|
||||
* This function is synchronous (i.e. uses polling).
|
||||
* c Character to send.
|
||||
*/
|
||||
void auxSerialPutc(const unsigned char c)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* Wait for the transmitter to be ready */
|
||||
while ( (pUart->UART_SR & UART_SR_TXRDY) == 0 ) ;
|
||||
|
||||
/* Send character */
|
||||
pUart->UART_THR = c;
|
||||
}
|
||||
|
||||
uint8_t auxSerialTracesEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 SECOND_UART_Configure(uint32_t baudrate, uint32_t masterClock)
|
||||
{
|
||||
Uart *pUart = SECOND_SERIAL_UART;
|
||||
|
||||
/* 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 << SECOND_SERIAL_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 SECOND_UART_Stop()
|
||||
{
|
||||
SECOND_SERIAL_UART->UART_IDR = UART_IDR_RXRDY ;
|
||||
NVIC_DisableIRQ(UART0_IRQn) ;
|
||||
}
|
||||
|
||||
extern "C" void UART0_IRQHandler()
|
||||
{
|
||||
if (SECOND_SERIAL_UART->UART_SR & UART_SR_RXRDY) {
|
||||
auxSerialRxFifo.push(SECOND_SERIAL_UART->UART_RHR);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define SECOND_UART_Configure(...)
|
||||
#endif
|
||||
|
||||
void auxSerialTelemetryInit(unsigned int /*protocol*/)
|
||||
{
|
||||
SECOND_UART_Configure(FRSKY_D_BAUDRATE, Master_frequency);
|
||||
}
|
||||
|
||||
bool telemetrySecondPortReceive(uint8_t & data)
|
||||
{
|
||||
return auxSerialRxFifo.pop(data);
|
||||
}
|
||||
|
||||
#if defined(DEBUG) && !defined(SIMU)
|
||||
void serialPrintf(const char*, ... ) {}
|
||||
#endif
|
||||
@@ -1,277 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void btSetBaudrate(uint32_t index)
|
||||
{
|
||||
uint32_t baudrate = (index==0 ? 115200 : (index==1 ? 9600 : 19200));
|
||||
UART3_Configure(baudrate, Master_frequency);
|
||||
}
|
||||
|
||||
void btInit()
|
||||
{
|
||||
btSetBaudrate(g_eeGeneral.bluetoothBaudrate);
|
||||
}
|
||||
|
||||
OS_FlagID btFlag;
|
||||
Fifo<32> btTxFifo;
|
||||
Fifo<32> btRxFifo;
|
||||
|
||||
struct t_serial_tx btTx ;
|
||||
uint8_t btTxBuffer[32] ;
|
||||
|
||||
struct t_serial_tx * Current_bt ;
|
||||
|
||||
uint32_t txPdcBt(struct t_serial_tx *data)
|
||||
{
|
||||
#ifndef SIMU
|
||||
Uart *pUart = BT_USART ;
|
||||
|
||||
if (pUart->UART_TNCR == 0) {
|
||||
Current_bt = data;
|
||||
data->ready = 1;
|
||||
pUart->UART_TPR = (uint32_t) data->buffer;
|
||||
pUart->UART_TCR = data->size;
|
||||
pUart->UART_PTCR = US_PTCR_TXTEN;
|
||||
pUart->UART_IER = UART_IER_TXBUFE;
|
||||
NVIC_EnableIRQ(UART1_IRQn);
|
||||
return 1; // Sent OK
|
||||
}
|
||||
#endif
|
||||
return 0 ; // Busy
|
||||
}
|
||||
|
||||
extern "C" void UART1_IRQHandler()
|
||||
{
|
||||
Uart *pUart = BT_USART ;
|
||||
if ( pUart->UART_SR & UART_SR_TXBUFE ) {
|
||||
pUart->UART_IDR = UART_IDR_TXBUFE ;
|
||||
pUart->UART_PTCR = US_PTCR_TXTDIS ;
|
||||
Current_bt->ready = 0 ;
|
||||
}
|
||||
if ( pUart->UART_SR & UART_SR_RXRDY ) {
|
||||
btRxFifo.push(pUart->UART_RHR);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t rxBtuart()
|
||||
{
|
||||
uint8_t result;
|
||||
if (!btRxFifo.pop(result))
|
||||
return 0xffff;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void btSendBuffer()
|
||||
{
|
||||
btTx.buffer = btTxBuffer;
|
||||
txPdcBt(&btTx);
|
||||
while (btTx.ready == 1) {
|
||||
RTOS_WAIT_TICKS(1);
|
||||
}
|
||||
btTx.size = 0;
|
||||
}
|
||||
|
||||
#define BT_POLL_TIMEOUT 500
|
||||
|
||||
uint32_t btChangeBaudrate( uint32_t baudIndex )
|
||||
{
|
||||
uint16_t x ;
|
||||
uint32_t y ;
|
||||
uint16_t rxchar ;
|
||||
|
||||
x = 4 ; // 9600
|
||||
if ( baudIndex == 0 )
|
||||
{
|
||||
x = 8 ; // 115200
|
||||
}
|
||||
else if ( baudIndex == 2 )
|
||||
{
|
||||
x = 5 ; // 19200
|
||||
}
|
||||
btTxBuffer[0] = 'A' ;
|
||||
btTxBuffer[1] = 'T' ;
|
||||
btTxBuffer[2] = '+' ;
|
||||
btTxBuffer[3] = 'B' ;
|
||||
btTxBuffer[4] = 'A' ;
|
||||
btTxBuffer[5] = 'U' ;
|
||||
btTxBuffer[6] = 'D' ;
|
||||
btTxBuffer[7] = '0' + x ;
|
||||
btTx.size = 8 ;
|
||||
btSendBuffer() ;
|
||||
x = 'O' ;
|
||||
for( y = 0 ; y < BT_POLL_TIMEOUT ; y += 1 ) {
|
||||
if ( ( rxchar = rxBtuart() ) != 0xFFFF ) {
|
||||
if ( rxchar == x ) {
|
||||
if ( x == 'O' ) {
|
||||
x = 'K' ;
|
||||
}
|
||||
else {
|
||||
break ; // Found "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
RTOS_WAIT_TICKS(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( y < BT_POLL_TIMEOUT ) {
|
||||
return 1 ;
|
||||
}
|
||||
else {
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t btPollDevice()
|
||||
{
|
||||
uint16_t x ;
|
||||
uint32_t y ;
|
||||
uint16_t rxchar ;
|
||||
|
||||
x = 'O' ;
|
||||
btTxBuffer[0] = 'A' ;
|
||||
btTxBuffer[1] = 'T' ;
|
||||
btTx.size = 2 ;
|
||||
btSendBuffer() ;
|
||||
|
||||
for( y = 0 ; y < BT_POLL_TIMEOUT ; y++) {
|
||||
if ( ( rxchar = rxBtuart() ) != 0xFFFF ) {
|
||||
if ( rxchar == x ) {
|
||||
if ( x == 'O' ) {
|
||||
x = 'K' ;
|
||||
}
|
||||
else {
|
||||
break ; // Found "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
RTOS_WAIT_TICKS(1) ; // 2mS
|
||||
}
|
||||
}
|
||||
|
||||
if ( y < BT_POLL_TIMEOUT ) {
|
||||
return 1 ;
|
||||
}
|
||||
else {
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Commands to BT module
|
||||
AT+VERSION Returns the software version of the module
|
||||
AT+BAUDx Sets the baud rate of the module:
|
||||
1 1200
|
||||
2 2400
|
||||
3 4800
|
||||
4 9600 (Default)
|
||||
5 19200
|
||||
6 38400
|
||||
7 57600
|
||||
8 115200
|
||||
9 230400
|
||||
AT+NAME<name here> Sets the name of the module
|
||||
|
||||
Any name can be specified up to 20 characters
|
||||
AT+PINxxxx Sets the pairing password of the device
|
||||
|
||||
Any 4 digit number can be used, the default pincode is 1234
|
||||
AT+PN Sets the parity of the module
|
||||
|
||||
So we could send AT+VERSION at different baudrates until we get a response
|
||||
Then we can change the baudrate to the required value.
|
||||
Or maybe just AT and get OK back
|
||||
*/
|
||||
|
||||
uint32_t btStatus;
|
||||
|
||||
void bluetoothTask(void * pdata)
|
||||
{
|
||||
uint8_t byte;
|
||||
|
||||
btFlag = CoCreateFlag(true, false);
|
||||
btTx.size = 0;
|
||||
|
||||
// Look for BT module baudrate, try 115200, and 9600
|
||||
// Already initialised to g_eeGeneral.bt_baudrate
|
||||
// 0 : 115200, 1 : 9600, 2 : 19200
|
||||
|
||||
uint32_t x = g_eeGeneral.bluetoothBaudrate;
|
||||
|
||||
btStatus = btPollDevice() ; // Do we get a response?
|
||||
|
||||
for (int y=0; y<2; y++) {
|
||||
if (btStatus == 0) {
|
||||
x += 1 ;
|
||||
if (x > 2) {
|
||||
x = 0 ;
|
||||
}
|
||||
btSetBaudrate(x) ;
|
||||
RTOS_WAIT_TICKS(1) ; // 2mS
|
||||
btStatus = btPollDevice() ; // Do we get a response?
|
||||
}
|
||||
}
|
||||
|
||||
if (btStatus) {
|
||||
btStatus = x + 1 ;
|
||||
if ( x != g_eeGeneral.bluetoothBaudrate ) {
|
||||
x = g_eeGeneral.bluetoothBaudrate ;
|
||||
// Need to change Bt Baudrate
|
||||
btChangeBaudrate( x ) ;
|
||||
btStatus += (x+1) * 10 ;
|
||||
btSetBaudrate( x ) ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
btInit();
|
||||
}
|
||||
|
||||
RTOS_WAIT_TICKS(1) ;
|
||||
|
||||
btPollDevice(); // Do we get a response?
|
||||
|
||||
while (1) {
|
||||
uint32_t x = CoWaitForSingleFlag(btFlag, 10); // Wait for data in Fifo
|
||||
if (x == E_OK) {
|
||||
// We have some data in the Fifo
|
||||
while (btTxFifo.pop(byte)) {
|
||||
btTxBuffer[btTx.size++] = byte;
|
||||
if (btTx.size > 31) {
|
||||
btSendBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (btTx.size) {
|
||||
btSendBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btPushByte(uint8_t data)
|
||||
{
|
||||
btTxFifo.push(data);
|
||||
CoSetFlag(btFlag); // Tell the Bt task something to do
|
||||
}
|
||||
@@ -1,494 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(PCBAR9X)
|
||||
#include "i2c_driver.h"
|
||||
#endif
|
||||
|
||||
uint16_t ResetReason;
|
||||
uint32_t Master_frequency ;
|
||||
volatile uint8_t lcdLock;
|
||||
volatile uint32_t lcdInputs;
|
||||
|
||||
uint16_t Current_analogue;
|
||||
uint16_t Current_max;
|
||||
uint32_t Current_accumulator;
|
||||
uint32_t Current_used;
|
||||
|
||||
extern "C" void sam_boot( void ) ;
|
||||
|
||||
// Prototype
|
||||
// Free pins (PA16 is stock buzzer)
|
||||
// PA23, PA24, PA25, PB7, PB13
|
||||
// PC20, PC21(labelled 17), PC22, PC24
|
||||
// REVB
|
||||
// PA25, use for stock buzzer
|
||||
// PB14, PB6
|
||||
// PC21, PC19, PC15 (PPM2 output)
|
||||
inline void config_free_pins()
|
||||
{
|
||||
configure_pins( PIO_PB14, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ;
|
||||
}
|
||||
|
||||
// Assumes PMC has already enabled clocks to ports
|
||||
inline void setup_switches()
|
||||
{
|
||||
configure_pins( 0x01808087, PIN_ENABLE | PIN_INPUT | PIN_PORTA | PIN_PULLUP ) ;
|
||||
configure_pins( 0x00000030, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ;
|
||||
configure_pins( 0x91114900, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP ) ;
|
||||
}
|
||||
|
||||
inline void UART3_Configure(uint32_t baudrate, uint32_t masterClock)
|
||||
{
|
||||
Uart *pUart = BT_USART;
|
||||
|
||||
/* Configure PIO */
|
||||
configure_pins( (PIO_PB2 | PIO_PB3), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTB | PIN_NO_PULLUP ) ;
|
||||
|
||||
/* Configure PMC */
|
||||
PMC->PMC_PCER0 = 1 << BT_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) + 8 ) / 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;
|
||||
|
||||
#if 0
|
||||
pUart->UART_IER = UART_IER_RXRDY ;
|
||||
NVIC_EnableIRQ(UART1_IRQn) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void UART3_Stop()
|
||||
{
|
||||
BT_USART->UART_IDR = UART_IDR_RXRDY ;
|
||||
NVIC_DisableIRQ(UART1_IRQn) ;
|
||||
}
|
||||
|
||||
// Starts TIMER0 at full speed (MCK/2) for delay timing
|
||||
// @ 36MHz this is 18MHz
|
||||
// This was 6 MHz, we may need to slow it to TIMER_CLOCK2 (MCK/8=4.5 MHz)
|
||||
inline void start_timer0()
|
||||
{
|
||||
Tc *ptc ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x00800000L ; // Enable peripheral clock to TC0
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 2 ;
|
||||
ptc->TC_CHANNEL[0].TC_CMR = 0x00008001 ; // Waveform mode MCK/8 for 36MHz osc.
|
||||
ptc->TC_CHANNEL[0].TC_RC = 0xFFF0 ;
|
||||
ptc->TC_CHANNEL[0].TC_RA = 0 ;
|
||||
ptc->TC_CHANNEL[0].TC_CMR = 0x00008040 ; // 0000 0000 0000 0000 1000 0000 0100 0000, stop at regC
|
||||
ptc->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
// TIMER2 at 200Hz, provides 5mS for sound and 10mS tick on interrupt
|
||||
// Starts TIMER2 at 200Hz, commentd out drive of TIOA2 (A26, EXT2)
|
||||
inline void start_timer2()
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x02000000L ; // Enable peripheral clock to TC2
|
||||
|
||||
timer = Master_frequency / 12800 / 2; // MCK/128 and 200 Hz
|
||||
|
||||
ptc = TC0 ; // Tc block 0 (TC0-2)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 0 ;
|
||||
ptc->TC_CHANNEL[2].TC_CMR = 0x00008000 ; // Waveform mode
|
||||
ptc->TC_CHANNEL[2].TC_RC = timer ; // 10 Hz
|
||||
ptc->TC_CHANNEL[2].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[2].TC_CMR = 0x0009C003 ; // 0000 0000 0000 1001 1100 0000 0000 0011
|
||||
ptc->TC_CHANNEL[2].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
|
||||
NVIC_EnableIRQ(TC2_IRQn) ;
|
||||
TC0->TC_CHANNEL[2].TC_IER = TC_IER0_CPCS ;
|
||||
}
|
||||
|
||||
void interrupt5ms()
|
||||
{
|
||||
static uint32_t pre_scale ; // Used to get 10 Hz counter
|
||||
|
||||
HAPTIC_HEARTBEAT();
|
||||
|
||||
if ( ++pre_scale >= 2 ) {
|
||||
BUZZER_HEARTBEAT();
|
||||
pre_scale = 0 ;
|
||||
per10ms();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void TC2_IRQHandler()
|
||||
{
|
||||
uint32_t dummy;
|
||||
|
||||
/* Clear status bit to acknowledge interrupt */
|
||||
dummy = TC0->TC_CHANNEL[2].TC_SR;
|
||||
(void) dummy ; // Discard value - prevents compiler warning
|
||||
|
||||
interrupt5ms();
|
||||
}
|
||||
|
||||
// PWM used for PPM generation, and LED Backlight
|
||||
// Output pin PB5 not used, PA17 used as PWMH3 peripheral C
|
||||
// PWM peripheral ID = 31 (0x80000000)
|
||||
// Ensure PB5 is three state/input, used on REVB for MENU KEY
|
||||
|
||||
// Configure PWM3 as PPM drive,
|
||||
// PWM0 is LED backlight PWM on PWMH0
|
||||
// This is PC18 peripheral B, Also enable PC22 peripheral B, this is PPM-JACK (PWML3)
|
||||
//
|
||||
// REVB board:
|
||||
// PWML2, output as peripheral C on PA16, is for HAPTIC
|
||||
// For testing, just drive it out with PWM
|
||||
// PWML1 for PPM2 output as peripheral B on PC15
|
||||
// For testing, just drive it out with PWM
|
||||
void init_pwm()
|
||||
{
|
||||
Pwm *pwmptr ;
|
||||
uint32_t timer ;
|
||||
|
||||
PMC->PMC_PCER0 |= ( 1 << ID_PWM ) ; // Enable peripheral clock to PWM
|
||||
|
||||
MATRIX->CCFG_SYSIO |= 0x00000020L ; // Disable TDO let PB5 work!
|
||||
|
||||
/* Configure PIO */
|
||||
configure_pins( PIO_PA16, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_C | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
|
||||
configure_pins( PIO_PC18, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_NO_PULLUP ) ;
|
||||
configure_pins( PIO_PC22, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_NO_PULLUP ) ;
|
||||
|
||||
// Configure clock - depends on MCK frequency
|
||||
timer = Master_frequency / 2000000 ;
|
||||
timer |= ( Master_frequency / ( 32* 10000 ) ) << 16 ;
|
||||
timer &= 0x00FF00FF ;
|
||||
|
||||
pwmptr = PWM ;
|
||||
pwmptr->PWM_CLK = 0x05000000 | timer ; // MCK for DIVA, DIVA = 18 gives 0.5uS clock period @35MHz // MCK/32 / timer = 10000Hz for CLKB
|
||||
|
||||
// PWM0 for LED backlight
|
||||
pwmptr->PWM_CH_NUM[0].PWM_CMR = 0x0000000C ; // CLKB
|
||||
pwmptr->PWM_CH_NUM[0].PWM_CPDR = 100 ; // Period
|
||||
pwmptr->PWM_CH_NUM[0].PWM_CPDRUPD = 100 ; // Period
|
||||
pwmptr->PWM_CH_NUM[0].PWM_CDTY = 40 ; // Duty
|
||||
pwmptr->PWM_CH_NUM[0].PWM_CDTYUPD = 40 ; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID0 ; // Enable channel 0
|
||||
|
||||
// PWM2 for HAPTIC drive 100Hz test
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CMR = 0x0000000C ; // CLKB
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CPDR = 100 ; // Period
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CPDRUPD = 100 ; // Period
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTY = 40 ; // Duty
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTYUPD = 40 ; // Duty
|
||||
pwmptr->PWM_OOV &= ~0x00040000 ; // Force low
|
||||
pwmptr->PWM_OSS = 0x00040000 ; // Force low
|
||||
// pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2
|
||||
}
|
||||
|
||||
// LCD i/o pins
|
||||
// LCD_RES PC27
|
||||
// LCD_CS1 PC26
|
||||
// LCD_E PC12
|
||||
// LCD_RnW PC13
|
||||
// LCD_A0 PC15
|
||||
// LCD_D0 PC0
|
||||
// LCD_D1 PC7
|
||||
// LCD_D2 PC6
|
||||
// LCD_D3 PC5
|
||||
// LCD_D4 PC4
|
||||
// LCD_D5 PC3
|
||||
// LCD_D6 PC2
|
||||
// LCD_D7 PC1
|
||||
|
||||
#define LCD_DATA 0x000000FFL
|
||||
#define LCD_A0 0x00000080L
|
||||
#define LCD_RnW 0x00002000L
|
||||
#define LCD_E 0x00001000L
|
||||
#define LCD_CS1 0x04000000L
|
||||
#define LCD_RES 0x08000000L
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config )
|
||||
{
|
||||
Pio * pioptr;
|
||||
|
||||
pioptr = PIOA + ((config & PIN_PORT_MASK) >> 6);
|
||||
if (config & PIN_PULLUP) {
|
||||
pioptr->PIO_PPDDR = pins;
|
||||
pioptr->PIO_PUER = pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_PUDR = pins;
|
||||
}
|
||||
|
||||
if (config & PIN_PULLDOWN) {
|
||||
pioptr->PIO_PUDR = pins;
|
||||
pioptr->PIO_PPDER = pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_PPDDR = pins;
|
||||
}
|
||||
|
||||
if (config & PIN_HIGH) {
|
||||
pioptr->PIO_SODR = pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_CODR = pins;
|
||||
}
|
||||
|
||||
if (config & PIN_INPUT) {
|
||||
pioptr->PIO_ODR = pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_OER = pins;
|
||||
}
|
||||
|
||||
if (config & PIN_PERI_MASK_L) {
|
||||
pioptr->PIO_ABCDSR[0] |= pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_ABCDSR[0] &= ~pins;
|
||||
}
|
||||
|
||||
if (config & PIN_PERI_MASK_H) {
|
||||
pioptr->PIO_ABCDSR[1] |= pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_ABCDSR[1] &= ~pins;
|
||||
}
|
||||
|
||||
if (config & PIN_ENABLE) {
|
||||
pioptr->PIO_PER = pins;
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_PDR = pins;
|
||||
}
|
||||
}
|
||||
|
||||
void opentxBootloader();
|
||||
|
||||
// Set up for volume control (TWI0)
|
||||
// Need PA3 and PA4 set to peripheral A
|
||||
#if !defined(PCBAR9X)
|
||||
void i2cInit()
|
||||
{
|
||||
Pio *pioptr;
|
||||
uint32_t timing;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00080000L ; // Enable peripheral clock to TWI0
|
||||
|
||||
TWI0->TWI_CR = TWI_CR_SWRST ; // Reset in case we are restarting
|
||||
|
||||
/* Configure PIO */
|
||||
pioptr = PIOA ;
|
||||
pioptr->PIO_ABCDSR[0] &= ~0x00000018 ; // Peripheral A
|
||||
pioptr->PIO_ABCDSR[1] &= ~0x00000018 ; // Peripheral A
|
||||
pioptr->PIO_PDR = 0x00000018 ; // Assign to peripheral
|
||||
|
||||
timing = Master_frequency * 5 / 1000000 ; // 5uS high and low
|
||||
timing += 15 - 4 ;
|
||||
timing /= 16 ;
|
||||
timing |= timing << 8 ;
|
||||
|
||||
TWI0->TWI_CWGR = 0x00040000 | timing ; // TWI clock set
|
||||
TWI0->TWI_CR = TWI_CR_MSEN | TWI_CR_SVDIS ; // Master mode enable
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
NVIC_EnableIRQ(TWI0_IRQn) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
Pio *pioptr ;
|
||||
|
||||
ResetReason = RSTC->RSTC_SR;
|
||||
|
||||
MATRIX->CCFG_SYSIO |= 0x000000F0L ; // Disable syspins, enable B4,5,6,7
|
||||
|
||||
PMC->PMC_PCER0 = (1<<ID_PIOC)|(1<<ID_PIOB)|(1<<ID_PIOA)|(1<<ID_UART0) ; // Enable clocks to PIOB and PIOA and PIOC and UART0
|
||||
|
||||
PIOC->PIO_PER = PIO_PC25 ; // Enable bit C25 (USB-detect)
|
||||
|
||||
pwrInit() ;
|
||||
|
||||
config_free_pins() ;
|
||||
|
||||
// Next section configures the key inputs on the LCD data
|
||||
pioptr = PIOC;
|
||||
pioptr->PIO_PER = 0x0000003BL ; // Enable bits 1,3,4,5, 0
|
||||
pioptr->PIO_OER = PIO_PC0 ; // Set bit 0 output
|
||||
pioptr->PIO_ODR = 0x0000003AL ; // Set bits 1, 3, 4, 5 input
|
||||
pioptr->PIO_PUER = 0x0000003AL ; // Set bits 1, 3, 4, 5 with pullups
|
||||
|
||||
pioptr = PIOB ;
|
||||
pioptr->PIO_PUER = PIO_PB5 ; // Enable pullup on bit B5 (MENU)
|
||||
pioptr->PIO_PER = PIO_PB5 ; // Enable bit B5
|
||||
|
||||
setup_switches() ;
|
||||
|
||||
// Enable PCK2 on PB3, This is for testing of Timer 2 working
|
||||
// It will be used as serial data to the Bluetooth module
|
||||
pioptr->PIO_ABCDSR[0] |= PIO_PB3 ; // Peripheral B
|
||||
pioptr->PIO_ABCDSR[1] &= ~PIO_PB3 ; // Peripheral B
|
||||
pioptr->PIO_PDR = PIO_PB3 ; // Assign to peripheral
|
||||
PMC->PMC_SCER |= 0x0400 ; // PCK2 enabled
|
||||
PMC->PMC_PCK[2] = 2 ; // PCK2 is PLLA
|
||||
|
||||
start_timer2() ;
|
||||
start_timer0() ;
|
||||
adcInit() ;
|
||||
init_pwm() ;
|
||||
|
||||
__enable_irq();
|
||||
|
||||
audioInit();
|
||||
|
||||
i2cInit();
|
||||
|
||||
eepromInit();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotaryEncoderInit();
|
||||
#endif
|
||||
|
||||
lcdInit();
|
||||
|
||||
init_SDcard();
|
||||
|
||||
#if defined(PCBAR9X)
|
||||
rtcInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t temperature = 0; // Raw temp reading
|
||||
uint8_t maxTemperature = 0 ; // Raw temp reading
|
||||
|
||||
void end_bt_tx_interrupt()
|
||||
{
|
||||
Uart *pUart = BT_USART ;
|
||||
pUart->UART_IDR = UART_IDR_TXBUFE ;
|
||||
NVIC_DisableIRQ(UART1_IRQn) ;
|
||||
}
|
||||
|
||||
uint16_t getCurrent()
|
||||
{
|
||||
static uint16_t Current ;
|
||||
static uint32_t Current_sum ;
|
||||
static uint8_t Current_count ;
|
||||
|
||||
Current_sum += anaIn(TX_CURRENT);
|
||||
if (++Current_count >= 50) {
|
||||
Current = Current_sum / 5 ;
|
||||
Current_sum = 0 ;
|
||||
Current_count = 0 ;
|
||||
}
|
||||
|
||||
uint32_t current_scale = 488 + g_eeGeneral.txCurrentCalibration ;
|
||||
return (current_scale * Current) / 8192;
|
||||
}
|
||||
|
||||
#define STICK_LV_GAIN 0x01
|
||||
#define STICK_LH_GAIN 0x02
|
||||
#define STICK_RV_GAIN 0x04
|
||||
#define STICK_RH_GAIN 0x08
|
||||
|
||||
#define GAIN_LV 0x00080000
|
||||
#define GAIN_LH 0x00000020
|
||||
#define GAIN_RV 0x20000000
|
||||
#define GAIN_RH 0x00000008
|
||||
|
||||
#define OFF_LV 0x00000200
|
||||
#define OFF_LH 0x00000004
|
||||
#define OFF_RV 0x00004000
|
||||
#define OFF_RH 0x00000002
|
||||
|
||||
void setSticksGain(uint8_t gains)
|
||||
{
|
||||
Adc *padc ;
|
||||
uint32_t gain ;
|
||||
uint32_t offset ;
|
||||
|
||||
gain = 0 ;
|
||||
offset = 0 ;
|
||||
padc = ADC ;
|
||||
|
||||
if ( gains & STICK_LV_GAIN ) {
|
||||
gain |= GAIN_LV ;
|
||||
offset |= OFF_LV ;
|
||||
}
|
||||
if ( gains & STICK_LH_GAIN ) {
|
||||
gain |= GAIN_LH ;
|
||||
offset |= OFF_LH ;
|
||||
}
|
||||
if ( gains & STICK_RV_GAIN ) {
|
||||
gain |= GAIN_RV ;
|
||||
offset |= OFF_RV ;
|
||||
}
|
||||
if ( gains & STICK_RH_GAIN ) {
|
||||
gain |= GAIN_RH ;
|
||||
offset |= OFF_RH ;
|
||||
}
|
||||
|
||||
padc->ADC_CGR = gain;
|
||||
padc->ADC_COR = offset;
|
||||
}
|
||||
|
||||
void calcConsumption()
|
||||
{
|
||||
Current_accumulator += Current_analogue ;
|
||||
static uint32_t OneSecTimer;
|
||||
if (++OneSecTimer >= 100) {
|
||||
OneSecTimer -= 100 ;
|
||||
Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled)
|
||||
Current_accumulator = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t getBatteryVoltage()
|
||||
{
|
||||
int32_t instant_vbat = anaIn(TX_VOLTAGE); // using filtered ADC value on purpose
|
||||
instant_vbat = (instant_vbat + instant_vbat*(g_eeGeneral.txVoltageCalibration)/128) * 4191;
|
||||
instant_vbat /= 5530;
|
||||
return (uint16_t)instant_vbat;
|
||||
}
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
pwrOff();
|
||||
}
|
||||
@@ -1,425 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_SKY9X_H_
|
||||
#define _BOARD_SKY9X_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "board_lowlevel.h"
|
||||
#include "audio_driver.h"
|
||||
#include "../opentx_constants.h"
|
||||
|
||||
#define CPU_FREQ 36000000
|
||||
|
||||
extern uint16_t ResetReason;
|
||||
|
||||
#define BOOTLOADER_SIZE 0x8000
|
||||
#define FIRMWARE_SIZE (256*1024)
|
||||
#define FIRMWARE_ADDRESS 0x00400000
|
||||
|
||||
// Board driver
|
||||
void boardInit();
|
||||
void boardOff();
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotaryEncoderInit();
|
||||
void rotaryEncoderEnd();
|
||||
|
||||
#if !defined(REVX) && !defined(PCBAR9X)
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
#define REA_DOWN() (0)
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
#define NUM_SWITCHES 7
|
||||
#define STORAGE_NUM_SWITCHES NUM_SWITCHES
|
||||
#define NUM_SWITCHES_POSITIONS 9
|
||||
|
||||
#if !defined(NUM_FUNCTIONS_SWITCHES)
|
||||
#define NUM_FUNCTIONS_SWITCHES 0
|
||||
#endif
|
||||
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_MENU,
|
||||
KEY_ENTER=KEY_MENU,
|
||||
KEY_EXIT,
|
||||
KEY_DOWN,
|
||||
KEY_MINUS = KEY_DOWN,
|
||||
KEY_UP,
|
||||
KEY_PLUS = KEY_UP,
|
||||
KEY_RIGHT,
|
||||
KEY_LEFT,
|
||||
|
||||
KEY_COUNT,
|
||||
KEY_MAX = KEY_COUNT - 1,
|
||||
|
||||
TRM_BASE,
|
||||
TRM_LH_DWN = TRM_BASE,
|
||||
TRM_LH_UP,
|
||||
TRM_LV_DWN,
|
||||
TRM_LV_UP,
|
||||
TRM_RV_DWN,
|
||||
TRM_RV_UP,
|
||||
TRM_RH_DWN,
|
||||
TRM_RH_UP,
|
||||
TRM_LAST = TRM_RH_UP,
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
#define IS_SHIFT_KEY(index) (false)
|
||||
#define IS_SHIFT_PRESSED() (false)
|
||||
|
||||
enum EnumSwitches
|
||||
{
|
||||
SW_ID0,
|
||||
SW_ID1,
|
||||
SW_ID2,
|
||||
SW_THR,
|
||||
SW_RUD,
|
||||
SW_ELE,
|
||||
SW_AIL,
|
||||
SW_GEA,
|
||||
SW_TRN,
|
||||
};
|
||||
#define IS_3POS(sw) ((sw) == 0)
|
||||
#define IS_TOGGLE(sw) ((sw) == SWSRC_TRN)
|
||||
|
||||
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_EXIT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
|
||||
#define KEYS_GPIO_PIN_MENU 0x00000020
|
||||
#define KEYS_GPIO_PIN_EXIT 0x01000000
|
||||
#define KEYS_GPIO_PIN_UP 0x00000002
|
||||
#define KEYS_GPIO_PIN_DOWN 0x00000020
|
||||
#define KEYS_GPIO_PIN_RIGHT 0x00000010
|
||||
#define KEYS_GPIO_PIN_LEFT 0x00000008
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_REG_LHL PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVU PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LHR PIOB->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RVD PIOC->PIO_PDSR
|
||||
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
|
||||
#endif
|
||||
|
||||
#if defined(REVX)
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#else
|
||||
#define TRIMS_GPIO_PIN_LHL 0x00800000
|
||||
#define TRIMS_GPIO_PIN_LVD 0x01000000
|
||||
#define TRIMS_GPIO_PIN_RVU 0x00000002
|
||||
#define TRIMS_GPIO_PIN_RHL 0x00000001
|
||||
#define TRIMS_GPIO_PIN_LHR 0x00000010
|
||||
#define TRIMS_GPIO_PIN_LVU 0x10000000
|
||||
#define TRIMS_GPIO_PIN_RVD 0x00000400
|
||||
#define TRIMS_GPIO_PIN_RHR 0x00000200
|
||||
#endif
|
||||
|
||||
// LCD driver
|
||||
#define LCD_W 128
|
||||
#define LCD_H 64
|
||||
#define LCD_DEPTH 1
|
||||
#define LCD_CONTRAST_MIN 10
|
||||
#define LCD_CONTRAST_MAX 45
|
||||
#define LCD_CONTRAST_DEFAULT 25
|
||||
void lcdInit();
|
||||
void lcdRefresh();
|
||||
#define lcdRefreshWait()
|
||||
void lcdSetRefVolt(uint8_t val);
|
||||
void lcdSetContrast();
|
||||
|
||||
// USB driver
|
||||
void usbMassStorage();
|
||||
|
||||
#if !defined(SIMU)
|
||||
void usbJoystickUpdate();
|
||||
#endif
|
||||
|
||||
#define PIN_ENABLE 0x001
|
||||
#define PIN_PERIPHERAL 0x000
|
||||
#define PIN_INPUT 0x002
|
||||
#define PIN_OUTPUT 0x000
|
||||
#define PIN_PULLUP 0x004
|
||||
#define PIN_NO_PULLUP 0x000
|
||||
#define PIN_PULLDOWN 0x008
|
||||
#define PIN_NO_PULLDOWN 0x000
|
||||
#define PIN_PERI_MASK_L 0x010
|
||||
#define PIN_PERI_MASK_H 0x020
|
||||
#define PIN_PER_A 0x000
|
||||
#define PIN_PER_B 0x010
|
||||
#define PIN_PER_C 0x020
|
||||
#define PIN_PER_D 0x030
|
||||
#define PIN_PORT_MASK 0x0C0
|
||||
#define PIN_PORTA 0x000
|
||||
#define PIN_PORTB 0x040
|
||||
#define PIN_PORTC 0x080
|
||||
#define PIN_LOW 0x000
|
||||
#define PIN_HIGH 0x100
|
||||
|
||||
// Telemetry port
|
||||
#define SECOND_USART USART0
|
||||
#define SECOND_ID ID_USART0
|
||||
#define SECOND_PINS { PINS_USART0 }
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config );
|
||||
uint16_t getCurrent();
|
||||
|
||||
extern uint16_t Current_analogue;
|
||||
extern uint16_t Current_max;
|
||||
extern uint32_t Current_accumulator;
|
||||
extern uint32_t Current_used;
|
||||
extern uint16_t sessionTimer;
|
||||
void calcConsumption();
|
||||
|
||||
// Trainer driver
|
||||
#define SLAVE_MODE() (pwrCheck() == e_power_trainer)
|
||||
void init_trainer_capture();
|
||||
void stop_trainer_capture();
|
||||
#define TRAINER_DETECT_GPIO PIOA
|
||||
#define TRAINER_DETECT_GPIO_PIN PIO_PA8
|
||||
#define TRAINER_CONNECTED() (TRAINER_DETECT_GPIO->PIO_PDSR & TRAINER_DETECT_GPIO_PIN)
|
||||
|
||||
// Write Flash driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
void flashWrite(uint32_t * address, const uint32_t * buffer);
|
||||
|
||||
// Keys driver
|
||||
uint32_t switchState(uint8_t index);
|
||||
uint32_t readKeys();
|
||||
uint32_t readTrims();
|
||||
#define NUM_TRIMS 4
|
||||
#define NUM_TRIMS_KEYS (NUM_TRIMS * 2)
|
||||
#define TRIMS_PRESSED() readTrims()
|
||||
#define KEYS_PRESSED() readKeys()
|
||||
|
||||
// Pulses driver
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted);
|
||||
void extmoduleSendNextFrame();
|
||||
void module_output_active();
|
||||
inline void EXTERNAL_MODULE_ON()
|
||||
{
|
||||
module_output_active();
|
||||
}
|
||||
|
||||
// SD driver
|
||||
#if defined(SIMU)
|
||||
#define sdInit()
|
||||
#define sdDone()
|
||||
#else
|
||||
#define sdPoll10ms()
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
void init_SDcard();
|
||||
void sdInit();
|
||||
void sdDone();
|
||||
uint32_t sd_card_ready();
|
||||
uint32_t sdMounted();
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// WDT driver
|
||||
#if !defined(WATCHDOG) || defined(SIMU)
|
||||
#define WDG_ENABLE(x)
|
||||
#define WDG_RESET()
|
||||
#define IS_RESET_REASON_WATCHDOG() false
|
||||
#else
|
||||
#define WDG_ENABLE(x) WDT->WDT_MR = 0x3FFF207F
|
||||
#define WDG_RESET() WDT->WDT_CR = 0xA5000001
|
||||
#define IS_RESET_REASON_WATCHDOG() ((ResetReason & RSTC_SR_RSTTYP) == (2 << 8))
|
||||
#endif
|
||||
|
||||
// Backlight driver
|
||||
#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = currentBacklightBright)
|
||||
#define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
|
||||
#define isBacklightEnabled() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
|
||||
#define BACKLIGHT_ENABLE() backlightEnable()
|
||||
#define BACKLIGHT_DISABLE() backlightDisable()
|
||||
#define BACKLIGHT_FORCED_ON 101
|
||||
|
||||
// ADC driver
|
||||
#define NUM_POTS 3
|
||||
#define STORAGE_NUM_POTS 3
|
||||
#define NUM_SLIDERS 0
|
||||
#define STORAGE_NUM_SLIDERS 0
|
||||
#define NUM_XPOTS 0
|
||||
#define NUM_MOUSE_ANALOGS 0
|
||||
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT_FIRST,
|
||||
POT1 = POT_FIRST,
|
||||
POT2,
|
||||
POT3,
|
||||
POT_LAST = POT3,
|
||||
TX_VOLTAGE,
|
||||
TX_CURRENT,
|
||||
NUM_ANALOGS
|
||||
};
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT1 = CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT2,
|
||||
CALIBRATED_POT3,
|
||||
CALIBRATED_POT_LAST = CALIBRATED_POT3,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT_LAST)
|
||||
#define IS_SLIDER(x) false
|
||||
#define STICKS_PWM_ENABLED() false
|
||||
void adcInit();
|
||||
void adcRead();
|
||||
uint16_t getAnalogValue(uint8_t index);
|
||||
void setSticksGain(uint8_t gains);
|
||||
inline void enableVBatBridge()
|
||||
{
|
||||
}
|
||||
inline void disableVBatBridge()
|
||||
{
|
||||
}
|
||||
|
||||
// Battery driver
|
||||
uint16_t getBatteryVoltage(); // returns current battery voltage in 10mV steps
|
||||
#define BATTERY_MIN 90 // 9V
|
||||
#define BATTERY_MAX 120 // 12V
|
||||
#define BATTERY_WARN 90 // 9V
|
||||
|
||||
// Buzzer driver
|
||||
void buzzerSound(uint8_t duration);
|
||||
void buzzerHeartbeat();
|
||||
#define BUZZER_HEARTBEAT buzzerHeartbeat
|
||||
|
||||
// i2c driver
|
||||
void i2cCheck();
|
||||
|
||||
// Coproc driver
|
||||
void coprocInit();
|
||||
void coprocWriteData(uint8_t *data, uint32_t size);
|
||||
#if defined(__cplusplus)
|
||||
void coprocReadData(bool onlytemp=false);
|
||||
#endif
|
||||
extern int8_t volumeRequired;
|
||||
|
||||
#if defined(COPROCESSOR)
|
||||
typedef struct {
|
||||
uint8_t read;
|
||||
int8_t valid;
|
||||
int8_t temp;
|
||||
int8_t maxtemp;
|
||||
} CoprocData;
|
||||
|
||||
extern CoprocData coprocData;
|
||||
#endif
|
||||
|
||||
// Haptic driver
|
||||
#define HAPTIC_PWM
|
||||
void hapticOff();
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
|
||||
// BlueTooth driver
|
||||
#if defined(BLUETOOTH)
|
||||
void btInit();
|
||||
void bluetoothTask(void * pdata);
|
||||
void btPushByte(uint8_t data);
|
||||
#endif
|
||||
|
||||
// Power driver
|
||||
#define TRAINER_PWR
|
||||
#define SOFT_PWR_CTRL
|
||||
void pwrInit();
|
||||
void pwrOff();
|
||||
void pwrOn();
|
||||
uint32_t pwrCheck();
|
||||
bool pwrPressed();
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
#define pwrForcePressed() (false)
|
||||
|
||||
// EEPROM driver
|
||||
#define EEPROM_SIZE (4*1024*1024/8)
|
||||
#define EEPROM_BLOCK_SIZE (4*1024)
|
||||
void eepromInit();
|
||||
uint8_t eepromReadStatus();
|
||||
uint8_t eepromIsTransferComplete();
|
||||
void eepromBlockErase(uint32_t address);
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size);
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
// Telemetry driver
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||
void telemetryPortSetDirectionOutput();
|
||||
void telemetryPortSetDirectionInput();
|
||||
void telemetryTransmitBuffer(const uint8_t * buffer, uint32_t size);
|
||||
void rxPdcUsart( void (*pChProcess)(uint8_t x) );
|
||||
void sportSendBuffer(const uint8_t * buffer, uint32_t size);
|
||||
|
||||
// Second UART driver
|
||||
void auxSerialTelemetryInit(unsigned int protocol);
|
||||
void auxSerialPutc(const unsigned char c);
|
||||
#if defined(__cplusplus)
|
||||
bool telemetrySecondPortReceive(uint8_t & data);
|
||||
#endif
|
||||
|
||||
extern const uint8_t BootCode[];
|
||||
|
||||
// Pulses driver
|
||||
#define HARDWARE_EXTRA_MODULE
|
||||
|
||||
#endif // _BOARD_SKY9X_H_
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \par Purpose
|
||||
*
|
||||
* Provides the low-level initialization function that gets called on chip startup.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/** Define clock timeout */
|
||||
#define CLOCK_TIMEOUT 5000
|
||||
/** Bit 29 must always be set to 1 when programming the CKGR_PLLAR register.*/
|
||||
#define PMC_PLLA_SET_BIT29 (0x1 << 29)
|
||||
/** Specifies the number of Slow Clock cycles x8 before the LOCKA bit is set in PMC_SR after CKGR_PLLAR is written.*/
|
||||
#define PMC_PLLA_COUNT (0xBF << 8)
|
||||
/** The PLLA Clock frequency is the PLLA input frequency multiplied by 8*/
|
||||
#define PMC_PLLA_MULTIPIER (0x07 << 16)
|
||||
/** PLLA Divider is bypassed.*/
|
||||
#define PMC_PLLA_DIV (0x01)
|
||||
|
||||
void revert_osc( void ) ;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local functions
|
||||
* returns master_frequency
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
// *** WARNING, this is called BEFORE .data and .bss have been initialised
|
||||
// *** GLOBAL variables are NOT useable
|
||||
|
||||
static uint32_t BOARD_ConfigurePmc(void)
|
||||
{
|
||||
/* TODO: configurate PLL in new way */
|
||||
//#if 0
|
||||
// uint32_t timeout = 0;
|
||||
// /** 1: Checking the Main Oscillator Frequency (Optional) and Initialize main oscillator */
|
||||
// /** 1.1 Initialize main oscillator */
|
||||
// // TODO:
|
||||
|
||||
// /** 2. Setting PLL and Divider*/
|
||||
// /** 2.1 Initialize PLLA*/
|
||||
// PMC->CKGR_PLLAR = ( PMC_PLLA_SET_BIT29 |
|
||||
// PMC_PLLA_MULTIPIER |
|
||||
// PMC_PLLA_COUNT |
|
||||
// PMC_PLLA_DIV
|
||||
// );
|
||||
// timeout = 0;
|
||||
// /** 2.2 Wait for the LOCKA bit to be set by polling the status register.*/
|
||||
// while (!(PMC->PMC_SR & PMC_SR_LOCKA) && (timeout++ < CLOCK_TIMEOUT));
|
||||
// /** 2.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3. Selection of Master Clock and Processor Clock*/
|
||||
// PMC->PMC_MCKR |= PMC_MCKR_PRES_CLK_2;
|
||||
|
||||
// /** 3.1 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// /** 3.2 PLLA Clock is selected */
|
||||
// PMC->PMC_MCKR = PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK;
|
||||
|
||||
// /** 3.3 wait for the MCKRDY bit to be set by polling the status register*/
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
//#endif
|
||||
|
||||
#if 1 // old as sam3u
|
||||
#define AT91C_CKGR_MUL_SHIFT 16
|
||||
//#define AT91C_CKGR_OUT_SHIFT 14
|
||||
#define AT91C_CKGR_PLLCOUNT_SHIFT 8
|
||||
#define AT91C_CKGR_DIV_SHIFT 0
|
||||
|
||||
// Settings at 72MHz/2 = 36MHz
|
||||
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST & (0x8 << 8))
|
||||
#define BOARD_PLLR ((1 << 29) | (0x5 << AT91C_CKGR_MUL_SHIFT) \
|
||||
| (0x1 << AT91C_CKGR_PLLCOUNT_SHIFT) | (0x2 << AT91C_CKGR_DIV_SHIFT))
|
||||
#define BOARD_MCKR (PMC_MCKR_CSS_PLLA_CLK)
|
||||
|
||||
// Define clock timeout
|
||||
#undef CLOCK_TIMEOUT
|
||||
#define CLOCK_TIMEOUT 0xFFFFFFFF
|
||||
|
||||
uint32_t timeout = 0 ;
|
||||
Pmc *pmcptr ;
|
||||
|
||||
pmcptr = PMC ;
|
||||
|
||||
/* Enable NRST reset
|
||||
************************************/
|
||||
//AT91C_BASE_RSTC->RSTC_RMR |= AT91C_RSTC_URSTEN;
|
||||
|
||||
/* Select external slow clock
|
||||
****************************/
|
||||
|
||||
|
||||
// if ((SUPC->SUPC_SR & SUPC_SR_OSCSEL) != SUPC_SR_OSCSEL_CRYST) {
|
||||
// SUPC->SUPC_CR = SUPC_CR_XTALSEL_CRYSTAL_SEL | ((uint32_t)0xA5 << 24);
|
||||
// timeout = 0;
|
||||
// while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL_CRYST) );
|
||||
// }
|
||||
|
||||
|
||||
/* Initialize main oscillator
|
||||
****************************/
|
||||
if(!(pmcptr->CKGR_MOR & CKGR_MOR_MOSCSEL))
|
||||
{
|
||||
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCXTS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
}
|
||||
|
||||
/* Switch to 3-20MHz Xtal oscillator */
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
/* Initialize PLLA 72 MHz */
|
||||
pmcptr->CKGR_PLLAR = BOARD_PLLR;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_LOCKA) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
|
||||
/* Initialize UTMI for USB usage, can be disabled if not using USB for the sake of saving power*/
|
||||
//AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_UPLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN;
|
||||
//timeout = 0;
|
||||
//while (!(PMC->PMC_SR & AT91C_PMC_LOCKU) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
/* Switch to fast clock
|
||||
**********************/
|
||||
// PMC->PMC_MCKR = (BOARD_MCKR & ~PMC_MCKR_CSS) | PMC_MCKR_CSS_MAIN_CLK;
|
||||
// timeout = 0;
|
||||
// while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
// Switch to PLLA as main clock 36MHz
|
||||
PMC->PMC_MCKR = BOARD_MCKR;
|
||||
timeout = 0;
|
||||
while (!(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT));
|
||||
|
||||
#endif
|
||||
return 36000000L; // Master_frequency
|
||||
}
|
||||
|
||||
void revert_osc()
|
||||
{
|
||||
uint32_t timeout = 0;
|
||||
Pmc *pmcptr;
|
||||
|
||||
pmcptr = PMC;
|
||||
|
||||
// Switch back to the internal oscillator
|
||||
pmcptr->CKGR_MOR = (0x37 << 16) | BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MOSCSELS) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS) | PMC_MCKR_CSS_SLOW_CLK;
|
||||
timeout = 0;
|
||||
while (!(pmcptr->PMC_SR & PMC_SR_MCKRDY) && (++timeout < CLOCK_TIMEOUT));
|
||||
|
||||
pmcptr->CKGR_PLLAR = 1 << 29; // Stop PLLA
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
// extern void sam_bootx( void ) ;
|
||||
// extern void dispUSB( void ) ;
|
||||
// extern uint32_t init
|
||||
// ReadTrims( void ) ;
|
||||
// extern void run_application( void ) ;
|
||||
|
||||
static void lowLevelUsbCheck( void )
|
||||
{
|
||||
PMC->PMC_PCER0 = (1<<ID_PIOC) ; // Enable clock to PIOC
|
||||
PIOC->PIO_PER = PIO_PC25 ; // Enable bit C25 (USB-detect)
|
||||
|
||||
uint32_t i ;
|
||||
for ( i = 0 ; i < 50 ; i += 1 ) {
|
||||
__asm("nop") ;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < 10 ; i += 1 ) {
|
||||
if ( PIOC->PIO_PDSR & 0x02000000 ) {
|
||||
PMC->PMC_PCDR0 = (1<<ID_PIOC) ; // Disable clock to PIOC
|
||||
dispUSB() ;
|
||||
sam_bootx() ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t x = initReadTrims() ;
|
||||
if ((x & 0x42) != 0x42) {
|
||||
run_application();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Performs the low-level initialization of the chip. This includes EFC,
|
||||
* master clock and watchdog configuration.
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint32_t SystemInit (void)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
lowLevelUsbCheck() ;
|
||||
#endif
|
||||
|
||||
// Set 2 cycle (1 WS) for Embedded Flash Access
|
||||
// Max clock is 38 MHz (1.8V VVDCORE)
|
||||
EFC->EEFC_FMR = (1 << 8) ;
|
||||
|
||||
// Configure PMC
|
||||
return BOARD_ConfigurePmc();
|
||||
}
|
||||
@@ -1,634 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
// TODO merge this file with board_sky9x.h
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "chip.h"
|
||||
#include "AT91SAM3S4.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "core_cm3.h"
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par
|
||||
/// This page lists several definition related to the board description.
|
||||
///
|
||||
/// Definitions
|
||||
/// - BOARD_NAME
|
||||
|
||||
/// Name of the board.
|
||||
// #define BOARD_NAME "AT91SAM3S-EK"
|
||||
/// Board definition.
|
||||
#define at91sam3sek
|
||||
/// Family definition (already defined).
|
||||
#define at91sam3s
|
||||
/// Core definition
|
||||
#define cortexm3
|
||||
|
||||
// TODO remove these definitions
|
||||
//#define BOARD_REV_A
|
||||
#define BOARD_REV_B
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par sam3s_ek_opfreq "SAM3S-EK - Operating frequencies"
|
||||
/// This page lists several definition related to the board operating frequency
|
||||
/// (when using the initialization done by board_lowlevel.c).
|
||||
///
|
||||
/// !Definitions
|
||||
/// - BOARD_MAINOSC
|
||||
/// - BOARD_MCK
|
||||
|
||||
/// Frequency of the board main oscillator.
|
||||
#define BOARD_MAINOSC 12000000
|
||||
|
||||
/// Master clock frequency (when using board_lowlevel.c).
|
||||
// #define BOARD_MCK 64000000
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ADC
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// Startup time max, return from Idle mode (in �s)
|
||||
#define ADC_STARTUP_TIME_MAX 15
|
||||
/// Track and hold Acquisition Time min (in ns)
|
||||
#define ADC_TRACK_HOLD_TIME_MIN 1200
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
|
||||
//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par sam3s_ek_piodef "SAM3S-EK - PIO definitions"
|
||||
/// This pages lists all the pio definitions contained in board.h. The constants
|
||||
/// are named using the following convention: PIN_* for a constant which defines
|
||||
/// a single Pin instance (but may include several PIOs sharing the same
|
||||
/// controller), and PINS_* for a list of Pin instances.
|
||||
///
|
||||
/// !ADC
|
||||
/// - PIN_ADC0_AD0
|
||||
/// - PIN_ADC0_AD1
|
||||
/// - PIN_ADC0_AD2
|
||||
/// - PIN_ADC0_AD3
|
||||
/// - PIN_ADC0_AD4
|
||||
/// - PIN_ADC0_AD5
|
||||
/// - PIN_ADC0_AD6
|
||||
/// - PIN_ADC0_AD7
|
||||
/// - PINS_ADC0
|
||||
///
|
||||
/// !UART
|
||||
/// - PINS_UART
|
||||
///
|
||||
/// !EBI
|
||||
/// - PIN_EBI_DATA_BUS
|
||||
/// - PIN_EBI_NCS0
|
||||
/// - PIN_EBI_NRD
|
||||
/// - PIN_EBI_NWE
|
||||
/// - PIN_EBI_ADDR_BUS
|
||||
/// - PIN_EBI_PSRAM_NBS
|
||||
/// - PIN_EBI_A1
|
||||
/// - PIN_EBI_LCD_RS
|
||||
///
|
||||
/// !LEDs
|
||||
/// - PIN_LED_0
|
||||
/// - PIN_LED_1
|
||||
/// - PIN_LED_2
|
||||
/// - PINS_LEDS
|
||||
///
|
||||
/// !MCI
|
||||
/// - PINS_MCI
|
||||
///
|
||||
/// !Push buttons
|
||||
/// - PIN_PUSHBUTTON_1
|
||||
/// - PIN_PUSHBUTTON_2
|
||||
/// - PINS_PUSHBUTTONS
|
||||
/// - PUSHBUTTON_BP1
|
||||
/// - PUSHBUTTON_BP2
|
||||
///
|
||||
/// !PWMC
|
||||
/// - PIN_PWMC_PWMH0
|
||||
/// - PIN_PWMC_PWML0
|
||||
/// - PIN_PWMC_PWMH1
|
||||
/// - PIN_PWMC_PWML1
|
||||
/// - PIN_PWMC_PWMH2
|
||||
/// - PIN_PWMC_PWML2
|
||||
/// - PIN_PWMC_PWMH3
|
||||
/// - PIN_PWMC_PWML3
|
||||
/// - PIN_PWM_LED0
|
||||
/// - PIN_PWM_LED1
|
||||
/// - PIN_PWM_LED2
|
||||
/// - CHANNEL_PWM_LED0
|
||||
/// - CHANNEL_PWM_LED1
|
||||
/// - CHANNEL_PWM_LED2
|
||||
///
|
||||
/// !SPI
|
||||
/// - PIN_SPI_MISO
|
||||
/// - PIN_SPI_MOSI
|
||||
/// - PIN_SPI_SPCK
|
||||
/// - PINS_SPI
|
||||
/// - PIN_SPI_NPCS0_PA11
|
||||
///
|
||||
/// ! SSC
|
||||
/// - PIN_SSC_TD
|
||||
/// - PIN_SSC_TK
|
||||
/// - PIN_SSC_TF
|
||||
/// - PINS_SSC_CODEC
|
||||
///
|
||||
/// ! PCK0
|
||||
/// - PIN_PCK0
|
||||
///
|
||||
/// !TWI
|
||||
/// - PIN_TWI_TWD0
|
||||
/// - PIN_TWI_TWCK0
|
||||
/// - PINS_TWI
|
||||
///
|
||||
/// !USART0
|
||||
/// - PIN_USART0_RXD
|
||||
/// - PIN_USART0_TXD
|
||||
/// - PIN_USART0_CTS
|
||||
/// - PIN_USART0_RTS
|
||||
/// - PIN_USART0_SCK
|
||||
///
|
||||
/// !USB
|
||||
/// - PIN_USB_PULLUP
|
||||
///
|
||||
|
||||
/// ADC_AD0 pin definition.
|
||||
#define PIN_ADC0_AD0 {1 << 21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD1 pin definition.
|
||||
#define PIN_ADC0_AD1 {1 << 30, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD2 pin definition.
|
||||
#define PIN_ADC0_AD2 {1 << 3, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD3 pin definition.
|
||||
#define PIN_ADC0_AD3 {1 << 4, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD4 pin definition.
|
||||
#define PIN_ADC0_AD4 {1 << 15, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD5 pin definition.
|
||||
#define PIN_ADC0_AD5 {1 << 16, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD6 pin definition.
|
||||
#define PIN_ADC0_AD6 {1 << 17, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
/// ADC_AD7 pin definition.
|
||||
#define PIN_ADC0_AD7 {1 << 18, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
|
||||
/// Pins ADC
|
||||
#define PINS_ADC PIN_ADC0_AD0, PIN_ADC0_AD1, PIN_ADC0_AD2, PIN_ADC0_AD3, PIN_ADC0_AD4, PIN_ADC0_AD5, PIN_ADC0_AD6, PIN_ADC0_AD7
|
||||
|
||||
/** UART pins (UTXD0 and URXD0) definitions, PA9,10. */
|
||||
#define PINS_UART {0x00000600, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
|
||||
/// EBI
|
||||
#define PIN_EBI_DATA_BUS {0xFF, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NRD {1 << 11, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NWE {1 << 8, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
|
||||
#define PIN_EBI_NCS0 {1 << 20, PIOB, ID_PIOB, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_PSRAM_ADDR_BUS {0x3f00fff, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_PSRAM_NBS {1 << 7, PIOB, ID_PIOB, PIO_PERIPH_B, PIO_PULLUP}, \
|
||||
{1 << 15, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_A1 {1 << 19, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
|
||||
#define PIN_EBI_NCS1 {1 << 15, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} /* LCD CS pin */
|
||||
#define PIN_EBI_LCD_RS {1 << 19, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP} /* LCD RS pin */
|
||||
|
||||
#ifdef BOARD_REV_A
|
||||
/** LED #0 pin definition. */
|
||||
#define PIN_LED_0 {1 << 20, PIOC, ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/** LED #1 pin definition. */
|
||||
#define PIN_LED_1 {1 << 21, PIOC, ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/** LED #2 pin definition. */
|
||||
#define PIN_LED_2 {1 << 22, PIOC, ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
#endif
|
||||
#ifdef BOARD_REV_B
|
||||
/** LED #0 pin definition. */
|
||||
#define PIN_LED_0 {1 << 19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/** LED #1 pin definition. */
|
||||
#define PIN_LED_1 {1 << 20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/** LED #2 pin definition. */
|
||||
#define PIN_LED_2 {1 << 20, PIOC, ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
#endif
|
||||
|
||||
/** List of all LEDs definitions. */
|
||||
#define PINS_LEDS PIN_LED_0, PIN_LED_1, PIN_LED_2
|
||||
|
||||
/** MCI pins definition. */
|
||||
#define PINS_MCI {0x3fUL << 26, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_PULLUP}
|
||||
/** MCI pin Card Detect. */
|
||||
#define PIN_MCI_CD {PIO_PB7, PIOB, ID_PIOB, PIO_INPUT, PIO_PULLUP}
|
||||
|
||||
/** Push button #0 definition. Attributes = pull-up + debounce + interrupt on rising edge. */
|
||||
#define PIN_PUSHBUTTON_1 {1 << 3, PIOB, ID_PIOB, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE}
|
||||
/** Push button #1 definition. Attributes = pull-up + debounce + interrupt on falling edge. */
|
||||
#define PIN_PUSHBUTTON_2 {1 << 12, PIOC, ID_PIOC, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE}
|
||||
/** List of all push button definitions. */
|
||||
#define PINS_PUSHBUTTONS PIN_PUSHBUTTON_1, PIN_PUSHBUTTON_2
|
||||
|
||||
/** Push button #1 index. */
|
||||
#define PUSHBUTTON_BP1 0
|
||||
/** Push button #2 index. */
|
||||
#define PUSHBUTTON_BP2 1
|
||||
|
||||
/// Simulated joystick LEFT index.
|
||||
#define JOYSTICK_LEFT 0
|
||||
/// Simulated joystick RIGHT index.
|
||||
#define JOYSTICK_RIGHT 1
|
||||
|
||||
/** PWMC PWM0 pin definition. */
|
||||
#define PIN_PWMC_PWMH0 {1 << 18, PIOC, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
#define PIN_PWMC_PWML0 {1 << 19, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
/** PWMC PWM1 pin definition. */
|
||||
#define PIN_PWMC_PWMH1 {1 << 19, PIOC, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
#define PIN_PWMC_PWML1 {1 << 20, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
/** PWMC PWM2 pin definition. */
|
||||
#define PIN_PWMC_PWMH2 {1 << 20, PIOC, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
#define PIN_PWMC_PWML2 {1 << 16, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_DEFAULT}
|
||||
/** PWMC PWM3 pin definition. */
|
||||
#define PIN_PWMC_PWMH3 {1 << 21, PIOC, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
#define PIN_PWMC_PWML3 {1 << 15, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_DEFAULT}
|
||||
/** PWM pin definition for LED0 */
|
||||
#define PIN_PWM_LED0 PIN_PWMC_PWMH0, PIN_PWMC_PWML0
|
||||
/** PWM pin definition for LED1 */
|
||||
#define PIN_PWM_LED1 PIN_PWMC_PWMH2, PIN_PWMC_PWML2
|
||||
/** PWM pin definition for LED2 */
|
||||
#define PIN_PWM_LED2 PIN_PWMC_PWMH3, PIN_PWMC_PWML3
|
||||
/** PWM channel for LED0 */
|
||||
#define CHANNEL_PWM_LED0 0
|
||||
/** PWM channel for LED1 */
|
||||
#define CHANNEL_PWM_LED1 2
|
||||
/** PWM channel for LED2 */
|
||||
#define CHANNEL_PWM_LED2 3
|
||||
|
||||
/** SPI MISO pin definition. */
|
||||
#define PIN_SPI_MISO {1 << 12, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/** SPI MOSI pin definition. */
|
||||
#define PIN_SPI_MOSI {1 << 13, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/** SPI SPCK pin definition. */
|
||||
#define PIN_SPI_SPCK {1 << 14, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/** SPI chip select pin definition. */
|
||||
#define PIN_SPI_NPCS0_PA11 {1 << 11, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
/** List of SPI pin definitions (MISO, MOSI & SPCK). */
|
||||
#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
|
||||
|
||||
/// SSC pins definition.
|
||||
#define PIN_SSC_TD {0x1 << 26, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_SSC_TK {0x1 << 28, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_SSC_TF {0x1 << 30, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PINS_SSC_CODEC PIN_SSC_TD, PIN_SSC_TK, PIN_SSC_TF
|
||||
|
||||
/// PCK0
|
||||
#define PIN_PCK0 {0x1 << 21, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
|
||||
|
||||
/// TWI pins definition.
|
||||
#define TWI_V3XX
|
||||
#define PIN_TWI_TWD0 {0x1 << 9, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_TWI_TWCK0 {0x1 << 10, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PINS_TWI0 PIN_TWI_TWD0, PIN_TWI_TWCK0
|
||||
#define PIN_TWI_TWD1 {0x1 << 24, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_TWI_TWCK1 {0x1 << 25, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PINS_TWI1 PIN_TWI_TWD1, PIN_TWI_TWCK1
|
||||
|
||||
/// USART0
|
||||
#define PIN_USART0_RXD {0x1 << 19, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART0_TXD {0x1 << 18, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART0_CTS {0x1 << 8, PIOB, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART0_RTS {0x1 << 7, PIOB, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART0_SCK {0x1 << 17, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
|
||||
/// USART1
|
||||
#define PIN_USART1_RXD {0x1 << 21, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART1_TXD {0x1 << 22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART1_CTS {0x1 << 25, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART1_RTS {0x1 << 24, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART1_EN {0x1 << 23, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
|
||||
|
||||
/// USB VBus monitoring pin definition.
|
||||
#ifdef BOARD_REV_A
|
||||
#define PIN_USB_VBUS {1 << 23, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
#endif
|
||||
#ifdef BOARD_REV_B
|
||||
#define PIN_USB_VBUS {1 << 21, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
#endif
|
||||
|
||||
#define usbPlugged() (PIOC->PIO_PDSR & PIO_PC25)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par sam3s_ek_extcomp "SAM3S-EK - External components"
|
||||
/// This page lists the definitions related to external on-board components
|
||||
/// located in the board.h file for the AT91SAM3S-EK.
|
||||
///
|
||||
/// !AT45 Dataflash Card
|
||||
/// - BOARD_AT45_A_SPI_BASE
|
||||
/// - BOARD_AT45_A_SPI_ID
|
||||
/// - BOARD_AT45_A_SPI_PINS
|
||||
/// - BOARD_AT45_A_SPI
|
||||
/// - BOARD_AT45_A_NPCS
|
||||
/// - BOARD_AT45_A_NPCS_PIN
|
||||
///
|
||||
/// !AT45 Dataflash (serial onboard DataFlash)
|
||||
/// - BOARD_AT45_B_SPI_BASE
|
||||
/// - BOARD_AT45_B_SPI_ID
|
||||
/// - BOARD_AT45_B_SPI_PINS
|
||||
/// - BOARD_AT45_B_SPI
|
||||
/// - BOARD_AT45_B_NPCS
|
||||
/// - BOARD_AT45_B_NPCS_PIN
|
||||
///
|
||||
/// !AT26 Serial Flash
|
||||
/// - BOARD_AT26_A_SPI_BASE
|
||||
/// - BOARD_AT26_A_SPI_ID
|
||||
/// - BOARD_AT26_A_SPI_PINS
|
||||
/// - BOARD_AT26_A_SPI
|
||||
/// - BOARD_AT26_A_NPCS
|
||||
/// - BOARD_AT26_A_NPCS_PIN
|
||||
///
|
||||
/// !SD Card
|
||||
/// - MCI2_INTERFACE
|
||||
/// - BOARD_SD_MCI_BASE
|
||||
/// - BOARD_SD_MCI_ID
|
||||
/// - BOARD_SD_PINS
|
||||
/// - BOARD_SD_SLOT
|
||||
///
|
||||
/// !PSRAM
|
||||
/// - BOARD_PSRAM_PINS
|
||||
///
|
||||
/// !LCD
|
||||
/// - BOARD_LCD_ILI9325
|
||||
/// - BOARD_LCD_PINS
|
||||
/// - BOARD_BACKLIGHT_PIN
|
||||
/// - BOARD_LCD_BASE
|
||||
/// - BOARD_LCD_RS
|
||||
/// - BOARD_LCD_WIDTH
|
||||
/// - BOARD_LCD_HEIGHT
|
||||
///
|
||||
/// !TouchScreen
|
||||
/// - BOARD_TSC_ADS7843
|
||||
/// - PIN_TCS_IRQ
|
||||
/// - PIN_TCS_BUSY
|
||||
/// - BOARD_TSC_SPI_BASE
|
||||
/// - BOARD_TSC_SPI_ID
|
||||
/// - BOARD_TSC_SPI_PINS
|
||||
/// - BOARD_TSC_NPCS
|
||||
/// - BOARD_TSC_NPCS_PIN
|
||||
///
|
||||
/// Base address of SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_A_SPI_BASE SPI0
|
||||
///// Identifier of SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_A_SPI_ID ID_SPI0
|
||||
///// Pins of the SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_A_SPI_PINS PINS_SPI0
|
||||
///// Dataflahs SPI number.
|
||||
//#define BOARD_AT45_A_SPI 0
|
||||
///// Chip select connected to the dataflash.
|
||||
//#define BOARD_AT45_A_NPCS 3
|
||||
///// Chip select pin connected to the dataflash.
|
||||
//#define BOARD_AT45_A_NPCS_PIN PIN_SPI0_NPCS3
|
||||
|
||||
/// Base address of SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_B_SPI_BASE SPI1
|
||||
///// Identifier of SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_B_SPI_ID ID_SPI1
|
||||
///// Pins of the SPI peripheral connected to the dataflash.
|
||||
//#define BOARD_AT45_B_SPI_PINS PINS_SPI1
|
||||
///// Dataflahs SPI number.
|
||||
//#define BOARD_AT45_B_SPI 1
|
||||
///// Chip select connected to the dataflash.
|
||||
//#define BOARD_AT45_B_NPCS 3
|
||||
///// Chip select pin connected to the dataflash.
|
||||
//#define BOARD_AT45_B_NPCS_PIN PIN_SPI1_NPCS3
|
||||
|
||||
/// Base address of SPI peripheral connected to the serialflash.
|
||||
//#define BOARD_AT26_A_SPI_BASE SPI0
|
||||
///// Identifier of SPI peripheral connected to the serialflash.
|
||||
//#define BOARD_AT26_A_SPI_ID ID_SPI0
|
||||
///// Pins of the SPI peripheral connected to the serialflash.
|
||||
//#define BOARD_AT26_A_SPI_PINS PINS_SPI0
|
||||
///// Serialflash SPI number.
|
||||
//#define BOARD_AT26_A_SPI 0
|
||||
///// Chip select connected to the serialflash.
|
||||
//#define BOARD_AT26_A_NPCS 3
|
||||
///// Chip select pin connected to the serialflash.
|
||||
//#define BOARD_AT26_A_NPCS_PIN PIN_SPI0_NPCS3
|
||||
|
||||
/// ISO7816
|
||||
/// - PIN_SMARTCARD_CONNECT
|
||||
/// - PIN_ISO7816_RSTMC
|
||||
/// - PINS_ISO7816
|
||||
|
||||
/// Smartcard detection pin
|
||||
//#define PIN_SMARTCARD_CONNECT {1 << 5, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
|
||||
/// PIN used for reset the smartcard
|
||||
//#define PIN_ISO7816_RSTMC {1 << 7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
|
||||
/// Pins used for connect the smartcard
|
||||
//#define PINS_ISO7816 PIN_USART0_TXD, PIN_USART0_SCK, PIN_ISO7816_RSTMC
|
||||
|
||||
/// Dma channel number
|
||||
#define BOARD_MCI_DMA_CHANNEL 0
|
||||
/// MCI0 DMA hardware handshaking ID
|
||||
#define DMA_HW_SRC_REQ_ID_MCI0 AT91C_HDMA_SRC_PER_0
|
||||
#define DMA_HW_DEST_REQ_ID_MCI0 AT91C_HDMA_DST_PER_0
|
||||
/// MCI1 DMA hardware handshaking ID
|
||||
#define DMA_HW_SRC_REQ_ID_MCI1 AT91C_HDMA_SRC_PER_13
|
||||
#define DMA_HW_DEST_REQ_ID_MCI1 AT91C_HDMA_DST_PER_13
|
||||
/// SD DMA hardware handshaking ID
|
||||
#define BOARD_SD_DMA_HW_SRC_REQ_ID DMA_HW_SRC_REQ_ID_MCI0
|
||||
#define BOARD_SD_DMA_HW_DEST_REQ_ID DMA_HW_DEST_REQ_ID_MCI0
|
||||
|
||||
|
||||
/// HS MCI interface
|
||||
#define MCI2_INTERFACE
|
||||
/// Base address of the MCI peripheral connected to the SD card.
|
||||
#define BOARD_SD_MCI_BASE MCI0//MCI
|
||||
///// Peripheral identifier of the MCI connected to the SD card.
|
||||
#define BOARD_SD_MCI_ID AT91C_ID_MCI0 ID_MCI0 //ID_MCI
|
||||
///// MCI pins that shall be configured to access the SD card.
|
||||
#define BOARD_SD_PINS PINS_MCI
|
||||
///// MCI slot to which the SD card is connected to.
|
||||
#define BOARD_SD_SLOT MCI_SD_SLOTA
|
||||
///// MCI Card Detect pin.
|
||||
#define BOARD_SD_PIN_CD PIN_MCI_CD
|
||||
|
||||
#define BLOCK_SIZE 512
|
||||
#define MSD_BUFFER_SIZE (12*BLOCK_SIZE) // Size of the MSD IO buffer in bytes (6K, more the better)
|
||||
#define SD_CARD_PRESENT() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
||||
|
||||
// States for initialising card
|
||||
#define SD_ST_ERR -1
|
||||
#define SD_ST_STARTUP 0
|
||||
#define SD_ST_EMPTY 1
|
||||
#define SD_ST_INIT1 2
|
||||
#define SD_ST_INIT2 3
|
||||
#define SD_ST_IDLE 4
|
||||
#define SD_ST_READY 5
|
||||
#define SD_ST_IDENT 6
|
||||
#define SD_ST_STBY 7
|
||||
#define SD_ST_TRAN 8
|
||||
#define SD_ST_DATA 9
|
||||
#define SD_ST_MOUNTED 10
|
||||
|
||||
extern uint32_t Cmd_A41_resp;
|
||||
extern int32_t Card_state;
|
||||
extern volatile uint32_t Card_initialized;
|
||||
extern uint32_t Card_CSD[4];
|
||||
extern uint32_t transSpeed;
|
||||
|
||||
#define OCR_SD_CCS (1UL << 30)
|
||||
|
||||
#define SD_CSD(csd, bitfield, bits) ((csd[3-(bitfield)/32] >> ((bitfield)%32)) & ((1 << (bits)) - 1))
|
||||
|
||||
#define SD_CSD_TRAN_SPEED(pSd) SD_CSD(pSd, 96, 8) ///< Max. data transfer rate
|
||||
|
||||
#define SD_CSD_C_SIZE(pSd) ((SD_CSD(pSd, 72, 2) << 10) + \
|
||||
(SD_CSD(pSd, 64, 8) << 2) + \
|
||||
SD_CSD(pSd, 62, 2)) ///< Device size
|
||||
|
||||
#define SD_CSD_C_SIZE_HC(csd) ((SD_CSD(csd, 64, 6) << 16) + \
|
||||
(SD_CSD(csd, 56, 8) << 8) + \
|
||||
SD_CSD(csd, 48, 8)) ///< Device size v2.0 High Capacity
|
||||
|
||||
#define SD_CSD_C_SIZE_MULT(pSd) SD_CSD(pSd, 47, 3) ///< Device size multiplier
|
||||
|
||||
#define SD_CSD_MULT(pSd) (1 << (SD_CSD_C_SIZE_MULT(pSd) + 2))
|
||||
|
||||
#define SD_CSD_READ_BL_LEN(pSd) SD_CSD(pSd, 80, 4) ///< Max. read data block length
|
||||
|
||||
#define SD_CSD_BLKLEN(pSd) (1 << (SD_CSD_READ_BL_LEN(pSd) - 9))
|
||||
|
||||
#define SD_CSD_BLOCKNR(pSd) ((SD_CSD_C_SIZE(pSd) + 1) * SD_CSD_MULT(pSd)) * SD_CSD_BLKLEN(pSd)
|
||||
|
||||
#define SD_CSD_BLOCKNR_HC(pSd) ((SD_CSD_C_SIZE_HC(pSd) + 1) * 1024)
|
||||
|
||||
#if !defined(SIMU)
|
||||
#define SD_IS_HC() (Cmd_A41_resp & OCR_SD_CCS)
|
||||
#define SD_GET_BLOCKNR() (SD_IS_HC() ? (SD_CSD_BLOCKNR_HC(Card_CSD)) : (SD_CSD_BLOCKNR(Card_CSD)))
|
||||
#define SD_GET_SPEED() (transSpeed)
|
||||
#else
|
||||
#define SD_IS_HC() (0)
|
||||
#define SD_GET_BLOCKNR() (0)
|
||||
#define SD_GET_SPEED() (0)
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par sam3s_ek_mem "SAM3S-EK - Memories"
|
||||
/// This page lists definitions related to internal & external on-board memories.
|
||||
///
|
||||
/// !Embedded Flash
|
||||
/// - BOARD_FLASH_EFC
|
||||
|
||||
/// Internal SRAM address
|
||||
#define AT91C_ISRAM AT91C_IRAM
|
||||
#define AT91C_ISRAM_SIZE 0x00008000
|
||||
|
||||
#define AT91C_IFLASH_SIZE (0x40000)
|
||||
#define AT91C_IFLASH_PAGE_SIZE (256) // Internal FLASH 0 Page Size: 256 bytes
|
||||
#define AT91C_IFLASH_NB_OF_PAGES (1024) // Internal FLASH 0 Number of Pages: 512
|
||||
#define AT91C_IFLASH_LOCK_REGION_SIZE (16384) // Internal FLASH 0 Lock Region Size: 16 Kbytes
|
||||
#define AT91C_IFLASH_NB_OF_LOCK_BITS (16) // Internal FLASH 0 Number of Lock Bits: 16
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \section sam3s_ek_extcomp "SAM3S-EK - External components"
|
||||
/// This page lists the definitions related to external on-board components
|
||||
/// located in the board.h file for the SAM3S-EK.
|
||||
///
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \par sam3s_ek_chipdef "SAM3S-EK - Individual chip definition"
|
||||
/// This page lists the definitions related to different chip's definition
|
||||
/// located in the board.h file for the SAM3S-EK.
|
||||
|
||||
/// DBGU
|
||||
#define BOARD_DBGU_ID ID_DBGU
|
||||
|
||||
/// Rtc
|
||||
#define BOARD_RTC_ID ID_RTC
|
||||
|
||||
/// Twi eeprom
|
||||
#define BOARD_ID_TWI_EEPROM ID_TWI1
|
||||
#define BOARD_BASE_TWI_EEPROM TWI1
|
||||
#define BOARD_PINS_TWI_EEPROM PINS_TWI1
|
||||
|
||||
/// USART
|
||||
#define BOARD_PIN_USART_RXD PIN_USART1_RXD
|
||||
#define BOARD_PIN_USART_TXD PIN_USART1_TXD
|
||||
#define BOARD_PIN_USART_CTS PIN_USART1_CTS
|
||||
#define BOARD_PIN_USART_RTS PIN_USART1_RTS
|
||||
#define BOARD_PIN_USART_EN PIN_USART1_EN
|
||||
#define BOARD_USART_BASE USART1
|
||||
#define BOARD_ID_USART ID_USART1
|
||||
|
||||
// BlueTooth
|
||||
#define BT_USART UART1
|
||||
#define BT_ID ID_UART1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define PIN_EBI_NANDOE {1 << 9, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NANDWE {1 << 10, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NANDCLE {1 << 17, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NANDALE {1 << 16, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
#define PIN_EBI_NANDIO {0x000000FF, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP}
|
||||
|
||||
/// Nandflash chip enable pin definition.
|
||||
#define BOARD_NF_CE_PIN {1 << 14, PIOC, ID_PIOC, PIO_OUTPUT_1, PIO_DEFAULT}
|
||||
/// Nandflash ready/busy pin definition.
|
||||
#define BOARD_NF_RB_PIN {1 << 18, PIOC, ID_PIOC, PIO_INPUT, PIO_PULLUP}
|
||||
|
||||
/// Nandflash controller peripheral pins definition.
|
||||
#define PINS_NANDFLASH PIN_EBI_NANDIO, BOARD_NF_CE_PIN, BOARD_NF_RB_PIN, PIN_EBI_NANDOE, \
|
||||
PIN_EBI_NANDWE, PIN_EBI_NANDCLE, PIN_EBI_NANDALE
|
||||
|
||||
/// Address for transferring command bytes to the nandflash.
|
||||
#define BOARD_NF_COMMAND_ADDR 0x60400000
|
||||
/// Address for transferring address bytes to the nandflash.
|
||||
#define BOARD_NF_ADDRESS_ADDR 0x60200000
|
||||
/// Address for transferring data bytes to the nandflash.
|
||||
#define BOARD_NF_DATA_ADDR 0x60000000
|
||||
|
||||
extern uint32_t Master_frequency ;
|
||||
|
||||
struct t_serial_tx
|
||||
{
|
||||
uint8_t *buffer ;
|
||||
uint16_t size ;
|
||||
volatile uint16_t ready ;
|
||||
};
|
||||
|
||||
#endif // _BOARD_H_
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t buzzerCount ;
|
||||
|
||||
void buzzerOn()
|
||||
{
|
||||
PIOA->PIO_SODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
|
||||
void buzzerOff()
|
||||
{
|
||||
PIOA->PIO_CODR = 0x02000000L ; // Set bit A25 ON
|
||||
}
|
||||
|
||||
void buzzerSound(uint8_t duration)
|
||||
{
|
||||
buzzerOn();
|
||||
buzzerCount = duration;
|
||||
}
|
||||
|
||||
void buzzerHeartbeat()
|
||||
{
|
||||
if (buzzerCount) {
|
||||
if (--buzzerCount == 0)
|
||||
buzzerOff();
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
/// !Purpose
|
||||
///
|
||||
/// Definition of AT91SAM3S4 characteristics and features
|
||||
///
|
||||
/// !Usage
|
||||
/// -# For ARM core feature, see "AT91SAM3S4 - ARM core features".
|
||||
/// -# For IP features, see "AT91SAM3S4 - IP features".
|
||||
/// -# For misc, see "AT91SAM3S4 - Misc".
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _CHIP_H_
|
||||
#define _CHIP_H_
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - ARM core features"
|
||||
/// This page lists several characteristics related to the ARM core
|
||||
///
|
||||
|
||||
//ARM core features
|
||||
|
||||
/// ARM core definition.
|
||||
#define cortexm3
|
||||
|
||||
/// family definition.
|
||||
#define at91sam3s
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - IP features"
|
||||
/// This page lists several characteristics related to the embedded IP
|
||||
///
|
||||
|
||||
//IP FEATURES
|
||||
|
||||
// EFC GPNVM number
|
||||
#define CHIP_EFC_NUM_GPNVMS 3
|
||||
|
||||
/// Indicates chip has an Enhanced EFC.
|
||||
#define CHIP_FLASH_EEFC
|
||||
|
||||
// DMA channels number
|
||||
#define CHIP_DMA_CHANNEL_NUM 4
|
||||
|
||||
// Indicate chip's MCI interface.
|
||||
#define MCI2_INTERFACE
|
||||
|
||||
// Indicate chip SSC has DMA interface.
|
||||
#define CHIP_SSC_DMA
|
||||
|
||||
// Indicate chip SPI has DMA interface.
|
||||
#define CHIP_SPI_DMA
|
||||
|
||||
/// Indicates chip has an UDP Full Speed.
|
||||
#define CHIP_USB_UDP
|
||||
|
||||
/// Indicates chip has an internal pull-up.
|
||||
#define CHIP_USB_PULLUP_INTERNAL
|
||||
|
||||
/// Number of USB endpoints
|
||||
#define CHIP_USB_NUMENDPOINTS 8
|
||||
|
||||
/// Endpoints max paxcket size
|
||||
#define CHIP_USB_ENDPOINTS_MAXPACKETSIZE(i) \
|
||||
((i == 0) ? 64 : \
|
||||
((i == 1) ? 64 : \
|
||||
((i == 2) ? 64 : \
|
||||
((i == 3) ? 64 : \
|
||||
((i == 4) ? 512 : \
|
||||
((i == 5) ? 512 : \
|
||||
((i == 6) ? 64 : \
|
||||
((i == 7) ? 64 : 0 ))))))))
|
||||
|
||||
/// Endpoints Number of Bank
|
||||
#define CHIP_USB_ENDPOINTS_BANKS(i) \
|
||||
((i == 0) ? 1 : \
|
||||
((i == 1) ? 2 : \
|
||||
((i == 2) ? 2 : \
|
||||
((i == 3) ? 1 : \
|
||||
((i == 4) ? 2 : \
|
||||
((i == 5) ? 2 : \
|
||||
((i == 6) ? 2 : \
|
||||
((i == 7) ? 2 : 0 ))))))))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "AT91SAM3S4 - Misc "
|
||||
/// This page lists misc features
|
||||
///
|
||||
|
||||
//Misc
|
||||
|
||||
#endif // _CHIP_H_
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
int8_t volumeRequired ;
|
||||
uint8_t coprocReadDataPending ;
|
||||
uint8_t coprocWriteDataPending ;
|
||||
uint8_t CoProc_appgo_pending ;
|
||||
uint8_t Volume_read ;
|
||||
CoprocData coprocData;
|
||||
bool get_onlytemp;
|
||||
#if !defined(SIMU)
|
||||
// TODO not used? static uint8_t *Twi_read_address ;
|
||||
#endif
|
||||
static uint8_t TwiOperation ;
|
||||
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_READ_COPROC 3
|
||||
#define TWI_COPROC_APPGO 4
|
||||
#define TWI_WAIT_STOP 5
|
||||
#define TWI_WRITE_COPROC 6
|
||||
|
||||
// Commands to the coprocessor bootloader/application
|
||||
#define TWI_CMD_PAGEUPDATE 0x01 // TWI Command to program a flash page
|
||||
#define TWI_CMD_EXECUTEAPP 0x02 // TWI Command to jump to the application program
|
||||
#define TWI_CMD_SETREAD_ADDRESS 0x03 // TWI Command to set address to read from
|
||||
#define TWI_CMD_WRITE_DATA 0x04 // TWI Command send data to the application
|
||||
#define COPROC_RX_BUXSIZE 22
|
||||
uint8_t Co_proc_status[COPROC_RX_BUXSIZE] ;
|
||||
uint8_t *coprocWriteDataPtr ;
|
||||
uint32_t coprocWriteDataSize ;
|
||||
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) { // Set volume to this value
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if (coprocReadDataPending) {
|
||||
coprocData.valid = 0 ;
|
||||
coprocReadDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00351000 ; // Device 35 and master is reading
|
||||
TwiOperation = TWI_READ_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Co_proc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = COPROC_RX_BUXSIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( CoProc_appgo_pending ) {
|
||||
CoProc_appgo_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_COPROC_APPGO ;
|
||||
TWI0->TWI_THR = TWI_CMD_EXECUTEAPP ; // Send appgo command
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( coprocWriteDataPending ) {
|
||||
coprocWriteDataPending = 0 ;
|
||||
TWI0->TWI_MMR = 0x00350000 ; // Device 35 and master is writing
|
||||
TwiOperation = TWI_WRITE_COPROC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)coprocWriteDataPtr ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = coprocWriteDataSize ;
|
||||
TWI0->TWI_THR = TWI_CMD_WRITE_DATA ; // Send write command
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
|
||||
void coprocReadData(bool onlytemp)
|
||||
{
|
||||
get_onlytemp = onlytemp;
|
||||
coprocReadDataPending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
void coprocWriteData(uint8_t *data, uint32_t size)
|
||||
{
|
||||
coprocWriteDataPtr = data;
|
||||
coprocWriteDataSize = size;
|
||||
coprocWriteDataPending = 1;
|
||||
__disable_irq();
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
if ( TwiOperation == TWI_READ_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_STOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
coprocData.valid = -1 ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_STOP )
|
||||
{
|
||||
coprocData.valid = 1 ;
|
||||
coprocData.read = Co_proc_status[0] ;
|
||||
if ( coprocData.read & 0x80 ) {
|
||||
// Bootloader
|
||||
CoProc_appgo_pending = 1 ; // Action application
|
||||
}
|
||||
else {
|
||||
// Got data from tiny app
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
if (!get_onlytemp) {
|
||||
utm.tm_sec = Co_proc_status[1] ;
|
||||
utm.tm_min = Co_proc_status[2] ;
|
||||
utm.tm_hour = Co_proc_status[3] ;
|
||||
utm.tm_mday = Co_proc_status[4] ;
|
||||
utm.tm_mon = Co_proc_status[5] - 1;
|
||||
utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - TM_YEAR_BASE;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
coprocData.temp = Co_proc_status[8];
|
||||
if (coprocData.temp > coprocData.maxtemp)
|
||||
coprocData.maxtemp = coprocData.temp;
|
||||
}
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY ) {
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
// if ( TwiOperation == TWI_WRITE_VOL )
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
if ( TwiOperation == TWI_WRITE_COPROC )
|
||||
{
|
||||
if ( TWI0->TWI_SR & TWI_SR_TXBUFE )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_TXBUFE ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS ; // Stop transfers
|
||||
TwiOperation = TWI_NONE ;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( TWI0->TWI_SR & TWI_SR_NACK )
|
||||
{
|
||||
}
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
@@ -1,868 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* define compiler specific symbols */
|
||||
#if defined ( __CC_ARM )
|
||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
||||
|
||||
#endif
|
||||
|
||||
uint32_t __get_PSP(void) ;
|
||||
void __set_PSP(uint32_t topOfProcStack) ;
|
||||
uint32_t __get_MSP(void) ;
|
||||
void __set_MSP(uint32_t mainStackPointer) ;
|
||||
uint32_t __REV16(uint16_t value) ;
|
||||
int32_t __REVSH(int16_t value) ;
|
||||
uint32_t __RBIT(uint32_t value) ;
|
||||
uint8_t __LDREXB(uint8_t *addr) ;
|
||||
uint16_t __LDREXH(uint16_t *addr) ;
|
||||
uint32_t __LDREXW(uint32_t *addr) ;
|
||||
uint32_t __STREXB(uint8_t value, uint8_t *addr) ;
|
||||
uint32_t __STREXH(uint16_t value, uint16_t *addr) ;
|
||||
uint32_t __STREXW(uint32_t value, uint32_t *addr) ;
|
||||
|
||||
uint32_t __get_BASEPRI(void) ;
|
||||
void __set_BASEPRI(uint32_t basePri) ;
|
||||
uint32_t __get_PRIMASK(void) ;
|
||||
void __set_PRIMASK(uint32_t priMask) ;
|
||||
uint32_t __get_FAULTMASK(void) ;
|
||||
void __set_FAULTMASK(uint32_t faultMask) ;
|
||||
uint32_t __get_CONTROL(void) ;
|
||||
void __set_CONTROL(uint32_t control) ;
|
||||
uint32_t __REV(uint32_t value) ;
|
||||
|
||||
void revert_osc( void ) ;
|
||||
void sam_boot( void ) ;
|
||||
void sam_bootx( void ) ;
|
||||
void run_application( void ) ;
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
|
||||
/**
|
||||
* @brief Return the Process Stack Pointer
|
||||
*
|
||||
* @return ProcessStackPointer
|
||||
*
|
||||
* Return the actual process stack pointer
|
||||
*/
|
||||
__ASM uint32_t __get_PSP(void)
|
||||
{
|
||||
mrs r0, psp
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Process Stack Pointer
|
||||
*
|
||||
* @param topOfProcStack Process Stack Pointer
|
||||
*
|
||||
* Assign the value ProcessStackPointer to the MSP
|
||||
* (process stack pointer) Cortex processor register
|
||||
*/
|
||||
__ASM void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
msr psp, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Main Stack Pointer
|
||||
*
|
||||
* @return Main Stack Pointer
|
||||
*
|
||||
* Return the current value of the MSP (main stack pointer)
|
||||
* Cortex processor register
|
||||
*/
|
||||
__ASM uint32_t __get_MSP(void)
|
||||
{
|
||||
mrs r0, msp
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Main Stack Pointer
|
||||
*
|
||||
* @param topOfMainStack Main Stack Pointer
|
||||
*
|
||||
* Assign the value mainStackPointer to the MSP
|
||||
* (main stack pointer) Cortex processor register
|
||||
*/
|
||||
__ASM void __set_MSP(uint32_t mainStackPointer)
|
||||
{
|
||||
msr msp, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse byte order in unsigned short value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in unsigned short value
|
||||
*/
|
||||
__ASM uint32_t __REV16(uint16_t value)
|
||||
{
|
||||
rev16 r0, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse byte order in signed short value with sign extension to integer
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in signed short value with sign extension to integer
|
||||
*/
|
||||
__ASM int32_t __REVSH(int16_t value)
|
||||
{
|
||||
revsh r0, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
#if (__ARMCC_VERSION < 400000)
|
||||
|
||||
/**
|
||||
* @brief Remove the exclusive lock created by ldrex
|
||||
*
|
||||
* Removes the exclusive lock which is created by ldrex.
|
||||
*/
|
||||
__ASM void __CLREX(void)
|
||||
{
|
||||
clrex
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Base Priority value
|
||||
*
|
||||
* @return BasePriority
|
||||
*
|
||||
* Return the content of the base priority register
|
||||
*/
|
||||
__ASM uint32_t __get_BASEPRI(void)
|
||||
{
|
||||
mrs r0, basepri
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Base Priority value
|
||||
*
|
||||
* @param basePri BasePriority
|
||||
*
|
||||
* Set the base priority register
|
||||
*/
|
||||
__ASM void __set_BASEPRI(uint32_t basePri)
|
||||
{
|
||||
msr basepri, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Priority Mask value
|
||||
*
|
||||
* @return PriMask
|
||||
*
|
||||
* Return state of the priority mask bit from the priority mask register
|
||||
*/
|
||||
__ASM uint32_t __get_PRIMASK(void)
|
||||
{
|
||||
mrs r0, primask
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Priority Mask value
|
||||
*
|
||||
* @param priMask PriMask
|
||||
*
|
||||
* Set the priority mask bit in the priority mask register
|
||||
*/
|
||||
__ASM void __set_PRIMASK(uint32_t priMask)
|
||||
{
|
||||
msr primask, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Fault Mask value
|
||||
*
|
||||
* @return FaultMask
|
||||
*
|
||||
* Return the content of the fault mask register
|
||||
*/
|
||||
__ASM uint32_t __get_FAULTMASK(void)
|
||||
{
|
||||
mrs r0, faultmask
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Fault Mask value
|
||||
*
|
||||
* @param faultMask faultMask value
|
||||
*
|
||||
* Set the fault mask register
|
||||
*/
|
||||
__ASM void __set_FAULTMASK(uint32_t faultMask)
|
||||
{
|
||||
msr faultmask, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Control Register value
|
||||
*
|
||||
* @return Control value
|
||||
*
|
||||
* Return the content of the control register
|
||||
*/
|
||||
__ASM uint32_t __get_CONTROL(void)
|
||||
{
|
||||
mrs r0, control
|
||||
bx lr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Control Register value
|
||||
*
|
||||
* @param control Control value
|
||||
*
|
||||
* Set the control register
|
||||
*/
|
||||
__ASM void __set_CONTROL(uint32_t control)
|
||||
{
|
||||
msr control, r0
|
||||
bx lr
|
||||
}
|
||||
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
|
||||
|
||||
#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
#pragma diag_suppress=Pe940
|
||||
|
||||
/**
|
||||
* @brief Return the Process Stack Pointer
|
||||
*
|
||||
* @return ProcessStackPointer
|
||||
*
|
||||
* Return the actual process stack pointer
|
||||
*/
|
||||
uint32_t __get_PSP(void)
|
||||
{
|
||||
__ASM("mrs r0, psp");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Process Stack Pointer
|
||||
*
|
||||
* @param topOfProcStack Process Stack Pointer
|
||||
*
|
||||
* Assign the value ProcessStackPointer to the MSP
|
||||
* (process stack pointer) Cortex processor register
|
||||
*/
|
||||
void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
__ASM("msr psp, r0");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Main Stack Pointer
|
||||
*
|
||||
* @return Main Stack Pointer
|
||||
*
|
||||
* Return the current value of the MSP (main stack pointer)
|
||||
* Cortex processor register
|
||||
*/
|
||||
uint32_t __get_MSP(void)
|
||||
{
|
||||
__ASM("mrs r0, msp");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Main Stack Pointer
|
||||
*
|
||||
* @param topOfMainStack Main Stack Pointer
|
||||
*
|
||||
* Assign the value mainStackPointer to the MSP
|
||||
* (main stack pointer) Cortex processor register
|
||||
*/
|
||||
void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
__ASM("msr msp, r0");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse byte order in unsigned short value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in unsigned short value
|
||||
*/
|
||||
uint32_t __REV16(uint16_t value)
|
||||
{
|
||||
__ASM("rev16 r0, r0");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse bit order of value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse bit order of value
|
||||
*/
|
||||
uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
__ASM("rbit r0, r0");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (8 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 8 bit values)
|
||||
*/
|
||||
uint8_t __LDREXB(uint8_t *addr)
|
||||
{
|
||||
__ASM("ldrexb r0, [r0]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (16 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 16 bit values
|
||||
*/
|
||||
uint16_t __LDREXH(uint16_t *addr)
|
||||
{
|
||||
__ASM("ldrexh r0, [r0]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (32 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 32 bit values
|
||||
*/
|
||||
uint32_t __LDREXW(uint32_t *addr)
|
||||
{
|
||||
__ASM("ldrex r0, [r0]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (8 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 8 bit values
|
||||
*/
|
||||
uint32_t __STREXB(uint8_t value, uint8_t *addr)
|
||||
{
|
||||
__ASM("strexb r0, r0, [r1]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (16 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 16 bit values
|
||||
*/
|
||||
uint32_t __STREXH(uint16_t value, uint16_t *addr)
|
||||
{
|
||||
__ASM("strexh r0, r0, [r1]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (32 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 32 bit values
|
||||
*/
|
||||
uint32_t __STREXW(uint32_t value, uint32_t *addr)
|
||||
{
|
||||
__ASM("strex r0, r0, [r1]");
|
||||
__ASM("bx lr");
|
||||
}
|
||||
|
||||
#pragma diag_default=Pe940
|
||||
|
||||
|
||||
#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
|
||||
#if !defined(BOOT)
|
||||
/**
|
||||
* @brief Return the Process Stack Pointer
|
||||
*
|
||||
* @return ProcessStackPointer
|
||||
*
|
||||
* Return the actual process stack pointer
|
||||
*/
|
||||
/*extern uint32_t __get_PSP(void) __attribute__( ( naked ) ); */
|
||||
uint32_t __get_PSP(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, psp\n\t"
|
||||
"MOV r0, %0 \n\t"
|
||||
"BX lr \n\t" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Process Stack Pointer
|
||||
*
|
||||
* @param topOfProcStack Process Stack Pointer
|
||||
*
|
||||
* Assign the value ProcessStackPointer to the MSP
|
||||
* (process stack pointer) Cortex processor register
|
||||
*/
|
||||
/*void __set_PSP(uint32_t topOfProcStack) __attribute__( ( naked ) ); */
|
||||
void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
__ASM volatile ("MSR psp, %0\n\t"
|
||||
"BX lr \n\t" : : "r" (topOfProcStack) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Main Stack Pointer
|
||||
*
|
||||
* @return Main Stack Pointer
|
||||
*
|
||||
* Return the current value of the MSP (main stack pointer)
|
||||
* Cortex processor register
|
||||
*/
|
||||
/*uint32_t __get_MSP(void) __attribute__( ( naked ) ); */
|
||||
uint32_t __get_MSP(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, msp\n\t"
|
||||
"MOV r0, %0 \n\t"
|
||||
"BX lr \n\t" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Main Stack Pointer
|
||||
*
|
||||
* @param topOfMainStack Main Stack Pointer
|
||||
*
|
||||
* Assign the value mainStackPointer to the MSP
|
||||
* (main stack pointer) Cortex processor register
|
||||
*/
|
||||
/*void __set_MSP(uint32_t topOfMainStack) __attribute__( ( naked ) ); */
|
||||
void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
__ASM volatile ("MSR msp, %0\n\t"
|
||||
"BX lr \n\t" : : "r" (topOfMainStack) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Base Priority value
|
||||
*
|
||||
* @return BasePriority
|
||||
*
|
||||
* Return the content of the base priority register
|
||||
*/
|
||||
uint32_t __get_BASEPRI(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Base Priority value
|
||||
*
|
||||
* @param basePri BasePriority
|
||||
*
|
||||
* Set the base priority register
|
||||
*/
|
||||
void __set_BASEPRI(uint32_t value)
|
||||
{
|
||||
__ASM volatile ("MSR basepri, %0" : : "r" (value) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Priority Mask value
|
||||
*
|
||||
* @return PriMask
|
||||
*
|
||||
* Return state of the priority mask bit from the priority mask register
|
||||
*/
|
||||
uint32_t __get_PRIMASK(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, primask" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Priority Mask value
|
||||
*
|
||||
* @param priMask PriMask
|
||||
*
|
||||
* Set the priority mask bit in the priority mask register
|
||||
*/
|
||||
void __set_PRIMASK(uint32_t priMask)
|
||||
{
|
||||
__ASM volatile ("MSR primask, %0" : : "r" (priMask) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Fault Mask value
|
||||
*
|
||||
* @return FaultMask
|
||||
*
|
||||
* Return the content of the fault mask register
|
||||
*/
|
||||
uint32_t __get_FAULTMASK(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Fault Mask value
|
||||
*
|
||||
* @param faultMask faultMask value
|
||||
*
|
||||
* Set the fault mask register
|
||||
*/
|
||||
void __set_FAULTMASK(uint32_t faultMask)
|
||||
{
|
||||
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the Control Register value
|
||||
*
|
||||
* @return Control value
|
||||
*
|
||||
* Return the content of the control register
|
||||
*/
|
||||
uint32_t __get_CONTROL(void)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("MRS %0, control" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Control Register value
|
||||
*
|
||||
* @param control Control value
|
||||
*
|
||||
* Set the control register
|
||||
*/
|
||||
void __set_CONTROL(uint32_t control)
|
||||
{
|
||||
__ASM volatile ("MSR control, %0" : : "r" (control) );
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Reverse byte order in integer value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in integer value
|
||||
*/
|
||||
uint32_t __REV(uint32_t value)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
/**
|
||||
* @brief Reverse byte order in unsigned short value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in unsigned short value
|
||||
*/
|
||||
uint32_t __REV16(uint16_t value)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse byte order in signed short value with sign extension to integer
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse byte order in signed short value with sign extension to integer
|
||||
*/
|
||||
int32_t __REVSH(int16_t value)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reverse bit order of value
|
||||
*
|
||||
* @param value value to reverse
|
||||
* @return reversed value
|
||||
*
|
||||
* Reverse bit order of value
|
||||
*/
|
||||
uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (8 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 8 bit value
|
||||
*/
|
||||
uint8_t __LDREXB(uint8_t *addr)
|
||||
{
|
||||
uint8_t result=0;
|
||||
|
||||
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (16 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 16 bit values
|
||||
*/
|
||||
uint16_t __LDREXH(uint16_t *addr)
|
||||
{
|
||||
uint16_t result=0;
|
||||
|
||||
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LDR Exclusive (32 bit)
|
||||
*
|
||||
* @param *addr address pointer
|
||||
* @return value of (*address)
|
||||
*
|
||||
* Exclusive LDR command for 32 bit values
|
||||
*/
|
||||
uint32_t __LDREXW(uint32_t *addr)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (8 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 8 bit values
|
||||
*/
|
||||
uint32_t __STREXB(uint8_t value, uint8_t *addr)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (16 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 16 bit values
|
||||
*/
|
||||
uint32_t __STREXH(uint16_t value, uint16_t *addr)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("strexh %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STR Exclusive (32 bit)
|
||||
*
|
||||
* @param value value to store
|
||||
* @param *addr address pointer
|
||||
* @return successful / failed
|
||||
*
|
||||
* Exclusive STR command for 32 bit values
|
||||
*/
|
||||
uint32_t __STREXW(uint32_t value, uint32_t *addr)
|
||||
{
|
||||
uint32_t result=0;
|
||||
|
||||
__ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOT)
|
||||
void run_application()
|
||||
{
|
||||
__ASM(" mov.w r1, #4227072"); // 0x408000
|
||||
__ASM(" movw r0, #60680"); // 0xED08
|
||||
__ASM(" movt r0, #57344"); // 0xE000
|
||||
__ASM(" str r1, [r0, #0]"); // Set the VTOR
|
||||
__ASM("ldr r0, [r1, #0]"); // Stack pointer value
|
||||
__ASM("msr msp, r0"); // Set it
|
||||
__ASM("ldr r0, [r1, #4]"); // Reset address
|
||||
__ASM("mov.w r1, #1");
|
||||
__ASM("orr r0, r1"); // Set lsbit
|
||||
__ASM("bx r0"); // Execute application
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOT)
|
||||
void sam_boot()
|
||||
{
|
||||
revert_osc() ;
|
||||
|
||||
__ASM(" mov.w r1, #8388608");
|
||||
__ASM(" movw r0, #60680");
|
||||
__ASM(" movt r0, #57344");
|
||||
__ASM(" str r1, [r0, #0]"); // Set the VTOR
|
||||
|
||||
__ASM("mov.w r3, #0");
|
||||
__ASM("movt r3, #128");
|
||||
__ASM("ldr r0, [r3, #0]");
|
||||
__ASM("msr msp, r0");
|
||||
__ASM("ldr r0, [r3, #4]");
|
||||
__ASM("mov.w r3, #1");
|
||||
__ASM("orr r0, r3");
|
||||
__ASM("bx r0");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOT)
|
||||
void sam_bootx()
|
||||
{
|
||||
__ASM(" mov.w r1, #8388608");
|
||||
__ASM(" movw r0, #60680");
|
||||
__ASM(" movt r0, #57344");
|
||||
__ASM(" str r1, [r0, #0]"); // Set the VTOR
|
||||
|
||||
__ASM("mov.w r3, #0");
|
||||
__ASM("movt r3, #128");
|
||||
__ASM("ldr r0, [r3, #0]");
|
||||
__ASM("msr msp, r0");
|
||||
__ASM("ldr r0, [r3, #4]");
|
||||
__ASM("mov.w r3, #1");
|
||||
__ASM("orr r0, r3");
|
||||
__ASM("bx r0");
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/
|
||||
/* TASKING carm specific functions */
|
||||
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all instrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define __CRT_C__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All extern Data */
|
||||
/*=========================================================================*/
|
||||
/*
|
||||
* The next data are defined by the linker script.
|
||||
*/
|
||||
extern unsigned long _stext;
|
||||
extern unsigned long _etext;
|
||||
extern unsigned long _sdata;
|
||||
extern unsigned long _edata;
|
||||
extern unsigned long _sbss;
|
||||
extern unsigned long _ebss;
|
||||
extern unsigned long _estack;
|
||||
|
||||
/* This is the main */
|
||||
extern int main (void);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: Prototypes */
|
||||
/*=========================================================================*/
|
||||
extern uint32_t SystemInit (void) ; // __attribute__((weak));
|
||||
|
||||
/*=========================================================================*/
|
||||
/* DEFINE: All code exported */
|
||||
/*=========================================================================*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* SystemInit */
|
||||
/* */
|
||||
/* SystemInit is a function which is provided by the CMSIS interface. */
|
||||
/* If this function is not available, we need a function here to prevent */
|
||||
/* an error of the linker. Therefore this function is declared as weak. */
|
||||
/***************************************************************************/
|
||||
//uint32_t SystemInit (void)
|
||||
//{
|
||||
|
||||
//} /* SystemInit */
|
||||
|
||||
extern uint32_t Master_frequency ;
|
||||
|
||||
/***************************************************************************/
|
||||
/* ResetHandler */
|
||||
/* */
|
||||
/* This function is used for the C runtime initialisation, */
|
||||
/* for handling the .data and .bss segments. */
|
||||
/***************************************************************************/
|
||||
void ResetHandler (void)
|
||||
{
|
||||
{
|
||||
uint32_t *pSrc;
|
||||
uint32_t *pDest;
|
||||
uint32_t m_freq ;
|
||||
|
||||
/*
|
||||
* Call the SystemInit code from CMSIS interface if available.
|
||||
* SystemInit is a week function which can be override
|
||||
* by an external function.
|
||||
*/
|
||||
m_freq = SystemInit();
|
||||
|
||||
/*
|
||||
* Set the "Vector Table Offset Register". From the ARM
|
||||
* documentation, we got the following information:
|
||||
*
|
||||
* Use the Vector Table Offset Register to determine:
|
||||
* - if the vector table is in RAM or code memory
|
||||
* - the vector table offset.
|
||||
*/
|
||||
*((uint32_t*)0xE000ED08) = (uint32_t)&_stext;
|
||||
|
||||
/*
|
||||
* Copy the initialized data of the ".data" segment
|
||||
* from the flash to the are in the ram.
|
||||
*/
|
||||
pSrc = &_etext;
|
||||
pDest = &_sdata;
|
||||
while(pDest < &_edata)
|
||||
{
|
||||
*pDest++ = *pSrc++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the ".bss" segment.
|
||||
*/
|
||||
pDest = &_sbss;
|
||||
while(pDest < &_ebss)
|
||||
{
|
||||
*pDest++ = 0;
|
||||
}
|
||||
Master_frequency = m_freq ;
|
||||
}
|
||||
|
||||
/*
|
||||
* And now the main function can be called.
|
||||
* Scotty, energie...
|
||||
*/
|
||||
main();
|
||||
|
||||
/*
|
||||
* In case there are problems with the
|
||||
* "warp drive", stop here.
|
||||
*/
|
||||
while(1) {};
|
||||
|
||||
} /* ResetHandler */
|
||||
|
||||
/*** EOF ***/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
volatile uint8_t Spi_complete = 1;
|
||||
uint8_t Spi_tx_buf[24];
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return Spi_complete;
|
||||
}
|
||||
|
||||
uint32_t eepromTransmitData(uint8_t *command, uint8_t *tx, uint8_t *rx, uint32_t comlen, uint32_t count)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t condition;
|
||||
static uint8_t discard_rx_command[4];
|
||||
|
||||
if (comlen > 4) {
|
||||
return 0x4FFFF;
|
||||
}
|
||||
|
||||
Spi_complete = 0;
|
||||
condition = SPI_SR_TXEMPTY;
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_RPR = (uint32_t)discard_rx_command;
|
||||
spiptr->SPI_RCR = comlen;
|
||||
if (rx) {
|
||||
spiptr->SPI_RNPR = (uint32_t)rx;
|
||||
spiptr->SPI_RNCR = count;
|
||||
condition = SPI_SR_RXBUFF;
|
||||
}
|
||||
spiptr->SPI_TPR = (uint32_t)command;
|
||||
spiptr->SPI_TCR = comlen;
|
||||
if (tx) {
|
||||
spiptr->SPI_TNPR = (uint32_t)tx;
|
||||
}
|
||||
else {
|
||||
spiptr->SPI_TNPR = (uint32_t)rx;
|
||||
}
|
||||
spiptr->SPI_TNCR = count;
|
||||
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTEN | SPI_PTCR_TXTEN; // Start transfers
|
||||
|
||||
// Wait for things to get started, avoids early interrupt
|
||||
for (count = 0; count < 1000; count += 1) {
|
||||
if ((spiptr->SPI_SR & SPI_SR_TXEMPTY) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
spiptr->SPI_IER = condition;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t eepromTransmitByte(uint8_t out, bool skipFirst)
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t delay;
|
||||
|
||||
spiptr->SPI_CR = 1; // Enable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
|
||||
spiptr->SPI_TDR = out;
|
||||
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipFirst) {
|
||||
(void) spiptr->SPI_RDR; // Dump the rx data
|
||||
spiptr->SPI_TDR = 0;
|
||||
delay = 0;
|
||||
while ((spiptr->SPI_SR & SPI_SR_RDRF) == 0) {
|
||||
// wait for received
|
||||
if (++delay > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
return spiptr->SPI_RDR;
|
||||
}
|
||||
|
||||
enum EepromCommand {
|
||||
COMMAND_WRITE_STATUS_REGISTER = 0x01,
|
||||
COMMAND_BYTE_PROGRAM = 0x02,
|
||||
COMMAND_READ_ARRAY = 0x03,
|
||||
COMMAND_READ_STATUS = 0x05,
|
||||
COMMAND_WRITE_ENABLE = 0x06,
|
||||
COMMAND_BLOCK_ERASE = 0x20,
|
||||
};
|
||||
|
||||
void eepromPrepareCommand(EepromCommand command, uint32_t address)
|
||||
{
|
||||
uint8_t * p = Spi_tx_buf;
|
||||
*p = command;
|
||||
*(p+1) = address >> 16;
|
||||
*(p+2) = address >> 8;
|
||||
*(p+3) = address;
|
||||
}
|
||||
|
||||
uint8_t eepromReadStatus()
|
||||
{
|
||||
uint8_t read_status = eepromTransmitByte(COMMAND_READ_STATUS, true);
|
||||
return !(read_status & 1);
|
||||
}
|
||||
|
||||
void eepromWriteStatusRegister()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_STATUS_REGISTER, true);
|
||||
}
|
||||
|
||||
void eepromWriteEnable()
|
||||
{
|
||||
eepromTransmitByte(COMMAND_WRITE_ENABLE, false);
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BYTE_PROGRAM, address);
|
||||
eepromTransmitData(Spi_tx_buf, buffer, 0, 4, size);
|
||||
}
|
||||
|
||||
void eepromStartRead(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromPrepareCommand(COMMAND_READ_ARRAY, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, buffer, 4, size);
|
||||
}
|
||||
|
||||
void eepromBlockErase(uint32_t address)
|
||||
{
|
||||
eepromWriteEnable();
|
||||
eepromPrepareCommand(COMMAND_BLOCK_ERASE, address);
|
||||
eepromTransmitData(Spi_tx_buf, 0, 0, 4, 0);
|
||||
}
|
||||
|
||||
// SPI i/f to EEPROM (4Mb)
|
||||
// Peripheral ID 21 (0x00200000)
|
||||
// Connections:
|
||||
// SS PA11 (peripheral A)
|
||||
// MISO PA12 (peripheral A)
|
||||
// MOSI PA13 (peripheral A)
|
||||
// SCK PA14 (peripheral A)
|
||||
// Set clock to 3 MHz, AT25 device is rated to 70MHz, 18MHz would be better
|
||||
void eepromInit()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
uint32_t timer;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00200000L; // Enable peripheral clock to SPI
|
||||
/* Configure PIO */
|
||||
configure_pins(0x00007800, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP);
|
||||
|
||||
timer = (Master_frequency / 3000000) << 8; // Baud rate 3Mb/s
|
||||
spiptr->SPI_MR = 0x14000011; // 0001 0100 0000 0000 0000 0000 0001 0001 Master
|
||||
spiptr->SPI_CSR[0] = 0x01180009 | timer; // 0000 0001 0001 1000 xxxx xxxx 0000 1001
|
||||
NVIC_EnableIRQ(SPI_IRQn);
|
||||
|
||||
eepromWriteEnable();
|
||||
eepromWriteStatusRegister();
|
||||
}
|
||||
|
||||
extern "C" void SPI_IRQHandler()
|
||||
{
|
||||
Spi * spiptr = SPI;
|
||||
SPI->SPI_IDR = 0x07FF; // All interrupts off
|
||||
spiptr->SPI_CR = 2; // Disable
|
||||
(void) spiptr->SPI_RDR; // Dump any rx data
|
||||
(void) spiptr->SPI_SR; // Clear error flags
|
||||
spiptr->SPI_PTCR = SPI_PTCR_RXTDIS | SPI_PTCR_TXTDIS; // Stop tramsfers
|
||||
Spi_complete = 1; // Indicate completion
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t (*IAP_Function)(uint32_t, uint32_t);
|
||||
|
||||
void flashWrite(uint32_t * address, const uint32_t * buffer) // size is 256 bytes
|
||||
{
|
||||
uint32_t FlashSectorNum;
|
||||
uint32_t flash_cmd = 0;
|
||||
|
||||
// Always initialise this here, setting a default doesn't seem to work
|
||||
IAP_Function = (uint32_t (*)(uint32_t, uint32_t)) *(( uint32_t *)0x00800008);
|
||||
FlashSectorNum = (uint32_t) address;
|
||||
FlashSectorNum >>= 8;// page size is 256 bytes
|
||||
FlashSectorNum &= 2047;// max page number
|
||||
|
||||
/* Send data to the sector here */
|
||||
for (int i=0; i<FLASH_PAGESIZE/4; i++) {
|
||||
*address++ = *buffer++;
|
||||
}
|
||||
|
||||
/* build the command to send to EEFC */
|
||||
flash_cmd = (0x5A << 24) | (FlashSectorNum << 8) | 0x03; //AT91C_MC_FCMD_EWP ;
|
||||
|
||||
__disable_irq();
|
||||
/* Call the IAP function with appropriate command */
|
||||
i = IAP_Function(0, flash_cmd);
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
uint32_t readLockBits()
|
||||
{
|
||||
// Always initialise this here, setting a default doesn't seem to work
|
||||
IAP_Function = (uint32_t (*)(uint32_t, uint32_t)) *(( uint32_t *)0x00800008);
|
||||
|
||||
uint32_t flash_cmd = (0x5A << 24) | 0x0A;//AT91C_MC_FCMD_GLB ;
|
||||
__disable_irq();
|
||||
(void) IAP_Function( 0, flash_cmd );
|
||||
__enable_irq();
|
||||
return EFC->EEFC_FRR;
|
||||
}
|
||||
|
||||
void clearLockBits()
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t flash_cmd = 0;
|
||||
|
||||
// Always initialise this here, setting a default doesn't seem to work
|
||||
IAP_Function = (uint32_t (*)(uint32_t, uint32_t)) *(( uint32_t *)0x00800008);
|
||||
for ( i = 0; i < 16; i += 1 )
|
||||
{
|
||||
flash_cmd = (0x5A << 24) | ((128*i) << 8) | 0x09; //AT91C_MC_FCMD_CLB ;
|
||||
__disable_irq();
|
||||
/* Call the IAP function with appropriate command */
|
||||
(void) IAP_Function( 0, flash_cmd );
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t isFirmwareStart(const uint8_t * buffer)
|
||||
{
|
||||
const uint32_t * block = (const uint32_t *)buffer;
|
||||
|
||||
if ((block[0] & 0xFFFE3000) != 0x20000000 ) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[1] & 0xFFF80000) != 0x00400000) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[2] & 0xFFF80000) != 0x00400000) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void hapticOff()
|
||||
{
|
||||
PWM->PWM_DIS = PWM_DIS_CHID2 ; // Disable channel 2
|
||||
PWM->PWM_OOV &= ~0x00040000 ; // Force low
|
||||
PWM->PWM_OSS |= 0x00040000 ; // Force low
|
||||
}
|
||||
|
||||
// pwmPercent 0-100
|
||||
void hapticOn( uint32_t pwmPercent )
|
||||
{
|
||||
Pwm *pwmptr ;
|
||||
|
||||
pwmptr = PWM ;
|
||||
|
||||
if (pwmPercent > 100) {
|
||||
pwmPercent = 100 ;
|
||||
}
|
||||
|
||||
pwmptr->PWM_CH_NUM[2].PWM_CDTYUPD = pwmPercent ; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID2 ; // Enable channel 2
|
||||
pwmptr->PWM_OSC = 0x00040000 ; // Enable output
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "twi.h"
|
||||
|
||||
#define I2C_CLK_FAST 400000
|
||||
|
||||
uint32_t fromBCD(uint8_t bcd_value)
|
||||
{
|
||||
return (((bcd_value & 0xF0) * 10) >> 4) + (bcd_value & 0x0F);
|
||||
}
|
||||
|
||||
uint8_t toBCD(uint32_t value)
|
||||
{
|
||||
div_t qr = div(value, 10);
|
||||
return (qr.quot << 4) + qr.rem;
|
||||
}
|
||||
|
||||
twi_packet getPacket(uint8_t chip, uint8_t* addr, uint8_t addr_len, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
twi_packet packet;
|
||||
packet.chip = chip;
|
||||
for (uint8_t i = 0; i < addr_len; ++i)
|
||||
packet.addr[i] = addr[i];
|
||||
packet.addr_length = addr_len;
|
||||
packet.buffer = buffer;
|
||||
packet.length = length;
|
||||
return packet;
|
||||
}
|
||||
|
||||
bool i2cInit()
|
||||
{
|
||||
//Enable Peripheral Clock
|
||||
PMC->PMC_PCER0 |= 0x00080000L;
|
||||
//Enable TWI PIOs
|
||||
Pio *pioptr;
|
||||
pioptr = PIOA;
|
||||
pioptr->PIO_ABCDSR[0] &= ~0x00000018; // Peripheral A
|
||||
pioptr->PIO_ABCDSR[1] &= ~0x00000018; // Peripheral A
|
||||
pioptr->PIO_PDR = 0x00000018; // Assign to peripheral
|
||||
|
||||
twi_enable_master_mode(TWI0);
|
||||
twi_options_t opt;
|
||||
opt.master_clk = Master_frequency;
|
||||
opt.speed = I2C_CLK_FAST;
|
||||
return twi_master_init(TWI0, &opt) == TWI_SUCCESS;
|
||||
}
|
||||
|
||||
void i2cCheck()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t i2cReadBuffer(uint8_t chip, uint8_t* addr, uint8_t addr_len, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
twi_packet packet(getPacket(chip, addr, addr_len, buffer, length));
|
||||
return twi_master_read(TWI0, &packet);
|
||||
}
|
||||
|
||||
uint32_t i2cWriteBuffer(uint8_t chip, uint8_t* addr, uint8_t addr_len, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
twi_packet packet(getPacket(chip, addr, addr_len, buffer, length));
|
||||
return twi_master_write(TWI0, &packet);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _I2C_DRIVER_H_
|
||||
#define _I2C_DRIVER_H_
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
uint32_t fromBCD(uint8_t bcd_value);
|
||||
uint8_t toBCD(uint32_t value);
|
||||
|
||||
bool i2cInit();
|
||||
uint32_t i2cReadBuffer(uint8_t chip, uint8_t *addr, uint8_t addr_len, uint8_t *buffer, uint32_t length);
|
||||
uint32_t i2cWriteBuffer(uint8_t chip, uint8_t *addr, uint8_t addr_len, uint8_t *buffer, uint32_t length);
|
||||
|
||||
#endif
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/hid-joystick/HIDDJoystickDriver.h"
|
||||
extern void HIDDJoystickDriver_Initialize();
|
||||
unsigned char HIDDJoystickDriver_ChangeJoystickState(const HIDDJoystickInputReport *report);
|
||||
extern void USBD_Connect(void);
|
||||
}
|
||||
|
||||
static void ConfigureUsbClock(void)
|
||||
{
|
||||
/* Enable PLLB for USB */
|
||||
PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(1)
|
||||
| CKGR_PLLBR_MULB(7)
|
||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||
while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); // TODO && (timeout++ < CLOCK_TIMEOUT));
|
||||
/* USB Clock uses PLLB */
|
||||
PMC->PMC_USB = PMC_USB_USBDIV(1) /* /2 */
|
||||
| PMC_USB_USBS; /* PLLB */
|
||||
}
|
||||
|
||||
void usbJoystickUpdate()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (usbPlugged()) {
|
||||
TRACE_DEBUG("usbJoystick\n\r");
|
||||
|
||||
if (!initialized) {
|
||||
ConfigureUsbClock();
|
||||
|
||||
HIDDJoystickDriver_Initialize();
|
||||
|
||||
// VBus_Configure();
|
||||
USBD_Connect();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
static uint8_t HID_Buffer[11];
|
||||
|
||||
HID_Buffer[0] = 0;
|
||||
HID_Buffer[1] = 0;
|
||||
HID_Buffer[2] = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ( channelOutputs[i+8] > 0 ) {
|
||||
HID_Buffer[0] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+16] > 0 ) {
|
||||
HID_Buffer[1] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+24] > 0 ) {
|
||||
HID_Buffer[2] |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
//analog values
|
||||
//uint8_t * p = HID_Buffer + 1;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
int16_t value = channelOutputs[i] / 8;
|
||||
if ( value > 127 ) value = 127;
|
||||
else if ( value < -127 ) value = -127;
|
||||
HID_Buffer[i+3] = static_cast<int8_t>(value);
|
||||
}
|
||||
|
||||
HIDDJoystickDriver_ChangeJoystickState((HIDDJoystickInputReport*)&HID_Buffer);
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
|
||||
// keys:
|
||||
// KEY_EXIT PA31 (PC24)
|
||||
// KEY_MENU PB6 (PB5)
|
||||
// KEY_DOWN LCD5 PC3 (PC5)
|
||||
// KEY_UP LCD6 PC2 (PC1)
|
||||
// KEY_RIGHT LCD4 PC4 (PC4)
|
||||
// KEY_LEFT LCD3 PC5 (PC3)
|
||||
// Reqd. bit 6 LEFT, 5 RIGHT, 4 UP, 3 DOWN 2 EXIT 1 MENU
|
||||
// LCD pins 5 DOWN, 4 RIGHT, 3 LEFT, 1 UP
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t x;
|
||||
uint32_t result = 0;
|
||||
|
||||
x = lcdLock ? lcdInputs : PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
x = ~x;
|
||||
|
||||
if (x & KEYS_GPIO_PIN_RIGHT)
|
||||
result |= 0x02 << KEY_RIGHT;
|
||||
if (x & KEYS_GPIO_PIN_UP)
|
||||
result |= 0x02 << KEY_UP;
|
||||
if (x & KEYS_GPIO_PIN_LEFT)
|
||||
result |= 0x02 << KEY_LEFT;
|
||||
if (x & KEYS_GPIO_PIN_DOWN)
|
||||
result |= 0x02 << KEY_DOWN;
|
||||
if (x & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 0x02 << KEY_EXIT;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 0x02 << KEY_MENU;
|
||||
|
||||
// TRACE("readKeys(): %x => %x", x, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 0x01;
|
||||
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 0x04;
|
||||
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 0x20;
|
||||
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 0x40;
|
||||
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 0x02;
|
||||
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 0x08;
|
||||
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 0x10;
|
||||
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 0x80;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
bool keyDown()
|
||||
{
|
||||
return readKeys() || REA_DOWN();
|
||||
}
|
||||
|
||||
void readKeysAndTrims()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
uint8_t index = 0;
|
||||
uint8_t keys_input = readKeys();
|
||||
for (i = 1; i < 7; i++) {
|
||||
keys[index].input(keys_input & (1 << i));
|
||||
++index;
|
||||
}
|
||||
|
||||
uint8_t trims_input = readTrims();
|
||||
for (i = 1; i < 256; i <<= 1) {
|
||||
keys[index].input(trims_input & i);
|
||||
++index;
|
||||
}
|
||||
|
||||
if ((keys_input || trims_input) && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) {
|
||||
// on keypress turn the light on
|
||||
resetBacklightTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t switchState(uint8_t index)
|
||||
{
|
||||
uint32_t a = PIOA->PIO_PDSR;
|
||||
uint32_t c = PIOC->PIO_PDSR;
|
||||
|
||||
uint32_t xxx = 0;
|
||||
|
||||
switch (index) {
|
||||
case SW_ELE:
|
||||
xxx = c & 0x80000000; // ELE_DR PC31
|
||||
break;
|
||||
|
||||
case SW_AIL:
|
||||
xxx = a & 0x00000004; // AIL-DR PA2
|
||||
break;
|
||||
|
||||
case SW_RUD:
|
||||
xxx = a & 0x00008000; // RUN_DR PA15
|
||||
break;
|
||||
// INP_G_ID1 INP_E_ID2
|
||||
// id0 0 1
|
||||
// id1 1 1
|
||||
// id2 1 0
|
||||
case SW_ID0:
|
||||
xxx = ~c & 0x00004000; // SW_IDL1 PC14
|
||||
break;
|
||||
case SW_ID1:
|
||||
xxx = (c & 0x00004000);
|
||||
if (xxx) xxx = (c & 0x00000800);
|
||||
break;
|
||||
case SW_ID2:
|
||||
xxx = ~c & 0x00000800; // SW_IDL2 PC11
|
||||
break;
|
||||
|
||||
case SW_GEA:
|
||||
xxx = c & 0x00010000; // SW_GEAR PC16
|
||||
break;
|
||||
|
||||
case SW_THR:
|
||||
xxx = c & 0x00100000; // SW_TCUT PC20
|
||||
break;
|
||||
|
||||
case SW_TRN:
|
||||
xxx = c & 0x00000100; // SW-TRAIN PC8
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return xxx;
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
// LCD i/o pins
|
||||
// LCD_RES PC27
|
||||
// LCD_CS1 PC26
|
||||
// LCD_E PC12
|
||||
// LCD_RnW PC13
|
||||
// LCD_A0 PC15
|
||||
// LCD_D0 PC0
|
||||
// LCD_D1 PC7
|
||||
// LCD_D2 PC6
|
||||
// LCD_D3 PC5
|
||||
// LCD_D4 PC4
|
||||
// LCD_D5 PC3
|
||||
// LCD_D6 PC2
|
||||
// LCD_D7 PC1
|
||||
|
||||
#define LCD_DATA 0x000000FFL
|
||||
#define LCD_A0 0x00000080L
|
||||
#define LCD_RnW 0x00002000L
|
||||
#define LCD_E 0x00001000L
|
||||
#define LCD_CS1 0x04000000L
|
||||
#define LCD_RES 0x08000000L
|
||||
|
||||
void lcdSendCtl(uint8_t val)
|
||||
{
|
||||
Pio *pioptr;
|
||||
|
||||
pioptr = PIOC;
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_CODR = LCD_CS1; // Select LCD
|
||||
#endif
|
||||
PIOA->PIO_CODR = LCD_A0;
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_CODR = LCD_RnW; // Write
|
||||
#endif
|
||||
pioptr->PIO_ODSR = val;
|
||||
|
||||
pioptr->PIO_SODR = LCD_E; // Start E pulse
|
||||
// Need a delay here (250nS)
|
||||
TC0->TC_CHANNEL[0].TC_CCR = 5; // Enable clock and trigger it (may only need trigger)
|
||||
while ( TC0->TC_CHANNEL[0].TC_CV < 9 ) // Value depends on MCK/2 (used 18MHz)
|
||||
{
|
||||
// Wait
|
||||
}
|
||||
pioptr->PIO_CODR = LCD_E; // End E pulse
|
||||
PIOA->PIO_SODR = LCD_A0; // Data
|
||||
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_SODR = LCD_CS1; // Deselect LCD
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcdInit()
|
||||
{
|
||||
Pio *pioptr;
|
||||
// /home/thus/txt/datasheets/lcd/KS0713.pdf
|
||||
// ~/txt/flieger/ST7565RV17.pdf from http://www.glyn.de/content.asp?wdid=132&sid=
|
||||
|
||||
// read the inputs, and lock the LCD lines
|
||||
lcdInputs = PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
lcdLock = 1;
|
||||
|
||||
configure_pins( LCD_A0, PIN_ENABLE | PIN_LOW | PIN_OUTPUT | PIN_PORTA | PIN_NO_PULLUP );
|
||||
pioptr = PIOC;
|
||||
#if defined(REVX)
|
||||
pioptr->PIO_PER = PIO_PC27 | PIO_PC12 | 0xFF;
|
||||
pioptr->PIO_CODR = LCD_E;
|
||||
pioptr->PIO_CODR = LCD_RnW | LCD_CS1; // No longer needed, used elsewhere
|
||||
#else
|
||||
pioptr->PIO_PER = PIO_PC27 | PIO_PC26 | PIO_PC13 | PIO_PC12 | 0xFF;
|
||||
pioptr->PIO_CODR = LCD_E | LCD_RnW | LCD_CS1;
|
||||
#endif
|
||||
pioptr->PIO_SODR = LCD_RES;
|
||||
pioptr->PIO_OER = PIO_PC27 | PIO_PC26 | PIO_PC13 | PIO_PC12 | 0xFF; // Set bits 27,26,13,12,7-0 output
|
||||
pioptr->PIO_OWER = 0x000000FFL; // Allow write to ls 8 bits in ODSR
|
||||
|
||||
TC0->TC_CHANNEL[0].TC_CCR = 5; // Enable clock and trigger it (may only need trigger)
|
||||
pioptr->PIO_CODR = LCD_RES; // Reset LCD
|
||||
while ( TC0->TC_CHANNEL[0].TC_CV < 500 ) ; // > 10us, Value depends on MCK/2 (used 18MHz)
|
||||
TC0->TC_CHANNEL[0].TC_CCR = 5; // Enable clock and trigger it (may only need trigger)
|
||||
pioptr->PIO_SODR = LCD_RES; // Remove LCD reset
|
||||
while ( TC0->TC_CHANNEL[0].TC_CV < 27000 ) ; // 1500us, Value depends on MCK/2 (used 18MHz)
|
||||
lcdSendCtl(0xe2); //Initialize the internal functions
|
||||
lcdSendCtl(0xae); //DON = 0: display OFF
|
||||
lcdSendCtl(0xa1); //ADC = 1: reverse direction(SEG132->SEG1)
|
||||
lcdSendCtl(0xA6); //REV = 0: non-reverse display
|
||||
lcdSendCtl(0xA4); //EON = 0: normal display. non-entire
|
||||
lcdSendCtl(0xA2); // Select LCD bias=0
|
||||
lcdSendCtl(0xC0); //SHL = 0: normal direction (COM1->COM64)
|
||||
lcdSendCtl(0x2F); //Control power circuit operation VC=VR=VF=1
|
||||
lcdSendCtl(0x25); //Select int resistance ratio R2 R1 R0 =5
|
||||
lcdSendCtl(0x81); //Set reference voltage Mode
|
||||
lcdSendCtl(0x22); // 24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
|
||||
|
||||
#if defined(REVX)
|
||||
// 200mS delay (only if not wdt reset)
|
||||
if ( ( ( ResetReason & RSTC_SR_RSTTYP ) != (2 << 8) ) && !globalData.unexpectedShutdown ) {
|
||||
for (uint32_t j = 0; j < 100; j += 1 ) {
|
||||
TC0->TC_CHANNEL[0].TC_CCR = 5; // Enable clock and trigger it (may only need trigger)
|
||||
while ( TC0->TC_CHANNEL[0].TC_CV < 36000 ) {
|
||||
// Value depends on MCK/2 (used 18MHz) give 2mS delay
|
||||
WDG_RESET(); // Wait
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lcdSendCtl(0xAF); // DON = 1: display ON
|
||||
|
||||
pioptr->PIO_ODR = 0x0000003AL; // Set bits 1, 3, 4, 5 input
|
||||
pioptr->PIO_PUER = 0x0000003AL; // Set bits 1, 3, 4, 5 with pullups
|
||||
pioptr->PIO_ODSR = 0; // Drive D0 low
|
||||
|
||||
lcdLock = 0;
|
||||
}
|
||||
|
||||
void lcdSetRefVolt(uint8_t val)
|
||||
{
|
||||
Pio *pioptr;
|
||||
pioptr = PIOC;
|
||||
|
||||
// read the inputs, and lock the LCD lines
|
||||
lcdInputs = PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
lcdLock = 1;
|
||||
|
||||
pioptr->PIO_OER = 0x0C00B0FFL; // Set bits 27,26,15,13,12,7-0 output
|
||||
|
||||
lcdSendCtl(0x81);
|
||||
if ( val == 0 )
|
||||
{
|
||||
val = 0x22;
|
||||
}
|
||||
lcdSendCtl(val);
|
||||
|
||||
pioptr->PIO_ODR = 0x000000FEL; // Set bits 1, 3, 4, 5 input
|
||||
pioptr->PIO_PUER = 0x000000FEL; // Set bits 1, 3, 4, 5 with pullups
|
||||
pioptr->PIO_ODSR = 0; // Drive D0 low
|
||||
|
||||
lcdLock = 0;
|
||||
}
|
||||
|
||||
void lcdRefresh()
|
||||
{
|
||||
Pio *pioptr;
|
||||
uint8_t *p = displayBuf;
|
||||
uint32_t y;
|
||||
uint32_t x;
|
||||
uint32_t z;
|
||||
uint32_t ebit;
|
||||
|
||||
ebit = LCD_E;
|
||||
|
||||
pioptr = PIOA;
|
||||
pioptr->PIO_PER = 0x00000080; // Enable bit 7 (LCD-A0)
|
||||
pioptr->PIO_OER = 0x00000080;// Set bit 7 output
|
||||
|
||||
// read the inputs, and lock the LCD lines
|
||||
lcdInputs = PIOC->PIO_PDSR; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP ()
|
||||
lcdLock = 1;
|
||||
|
||||
pioptr = PIOC;
|
||||
pioptr->PIO_OER = 0x0C0030FFL; // Set bits 27,26,15,13,12,7-0 output
|
||||
for (y = 0; y < 8; y++) {
|
||||
lcdSendCtl(g_eeGeneral.optrexDisplay ? 0 : 0x04);
|
||||
lcdSendCtl(0x10); //column addr 0
|
||||
lcdSendCtl(y | 0xB0); //page addr y
|
||||
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_CODR = LCD_CS1; // Select LCD
|
||||
#endif
|
||||
PIOA->PIO_SODR = LCD_A0; // Data
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_CODR = LCD_RnW; // Write
|
||||
#endif
|
||||
|
||||
x = *p;
|
||||
for (z = 0; z < LCD_W; z += 1) {
|
||||
pioptr->PIO_ODSR = x;
|
||||
pioptr->PIO_SODR = ebit; // Start E pulse
|
||||
// Need a delay here (250nS)
|
||||
p += 1;
|
||||
x = *p;
|
||||
// TC0->TC_CHANNEL[0].TC_CCR = 5; // Enable clock and trigger it (may only need trigger)
|
||||
// while ( TC0->TC_CHANNEL[0].TC_CV < 3 ) // Value depends on MCK/2 (used 6MHz)
|
||||
// {
|
||||
// // Wait
|
||||
// }
|
||||
pioptr->PIO_CODR = ebit; // End E pulse
|
||||
}
|
||||
#if !defined(REVX)
|
||||
pioptr->PIO_SODR = LCD_CS1; // Deselect LCD
|
||||
#endif
|
||||
}
|
||||
|
||||
pioptr->PIO_ODSR = 0xFF; // Drive lines high
|
||||
pioptr->PIO_PUER = 0x000000FEL; // Set bits 1, 3, 4, 5 with pullups
|
||||
pioptr->PIO_ODR = 0x000000FEL; // Set bits 1, 3, 4, 5 input
|
||||
pioptr->PIO_ODSR = 0xFE; // Drive D0 low
|
||||
lcdLock = 0;
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#ifndef SIMU
|
||||
|
||||
extern "C" {
|
||||
#include "usb/device/massstorage/MSDDriver.h"
|
||||
extern unsigned char MEDSdcard_Initialize(Media *media, unsigned char mciID);
|
||||
}
|
||||
|
||||
/** LUN read/write buffer. */
|
||||
unsigned char msdBuffer[MSD_BUFFER_SIZE];
|
||||
|
||||
unsigned int msdReadTotal=0, msdWriteTotal=0;
|
||||
|
||||
static void ConfigureUsbClock(void)
|
||||
{
|
||||
/* Enable PLLB for USB */
|
||||
PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(1)
|
||||
| CKGR_PLLBR_MULB(7)
|
||||
| CKGR_PLLBR_PLLBCOUNT_Msk;
|
||||
while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); // TODO && (timeout++ < CLOCK_TIMEOUT));
|
||||
/* USB Clock uses PLLB */
|
||||
PMC->PMC_USB = PMC_USB_USBDIV(1) /* /2 */
|
||||
| PMC_USB_USBS; /* PLLB */
|
||||
}
|
||||
|
||||
/** Maximum number of LUNs which can be defined. */
|
||||
#define MAX_LUNS 1
|
||||
|
||||
/** Media index for different disks */
|
||||
#define DRV_SDMMC 0 /** SD card */
|
||||
|
||||
Media medias[MAX_LUNS];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local variables
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/** Device LUNs. */
|
||||
MSDLun luns[MAX_LUNS];
|
||||
|
||||
int itoa(int val, char* buf)
|
||||
{
|
||||
const unsigned int radix = 10;
|
||||
|
||||
char* p;
|
||||
unsigned int a; //every digit
|
||||
int len;
|
||||
char* b; //start of the digit char
|
||||
char temp;
|
||||
unsigned int u;
|
||||
|
||||
p = buf;
|
||||
|
||||
#if 0
|
||||
if (val < 0)
|
||||
{
|
||||
*p++ = '-';
|
||||
val = 0 - val;
|
||||
}
|
||||
#endif
|
||||
|
||||
u = (unsigned int)val;
|
||||
|
||||
b = p;
|
||||
|
||||
do
|
||||
{
|
||||
a = u % radix;
|
||||
u /= radix;
|
||||
|
||||
*p++ = a + '0';
|
||||
|
||||
} while (u > 0);
|
||||
|
||||
len = (int)(p - buf);
|
||||
|
||||
*p-- = 0;
|
||||
|
||||
//swap
|
||||
do
|
||||
{
|
||||
temp = *p;
|
||||
*p = *b;
|
||||
*b = temp;
|
||||
--p;
|
||||
++b;
|
||||
|
||||
} while (b < p);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t write_bytes(char *str, uint32_t bytes)
|
||||
{
|
||||
uint8_t len;
|
||||
if (bytes < 1024*100) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % 1024) / 103);
|
||||
str[len+2] = 'K';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else if (bytes < 1024*1024) {
|
||||
len = itoa(bytes / 1024, str);
|
||||
str[len] = 'K';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
else if (bytes < 1024*1024*100) {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = '.';
|
||||
str[len+1] = '0' + ((bytes % (1024*1024)) / 104858);
|
||||
str[len+2] = 'M';
|
||||
str[len+3] = '\0';
|
||||
len += 3;
|
||||
}
|
||||
else {
|
||||
len = itoa(bytes / (1024*1024), str);
|
||||
str[len] = 'M';
|
||||
str[len+1] = '\0';
|
||||
len += 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static void MSDCallbacks_Data( unsigned char flowDirection, unsigned int dataLength,
|
||||
unsigned int fifoNullCount, unsigned int fifoFullCount )
|
||||
{
|
||||
if (flowDirection)
|
||||
msdReadTotal += dataLength;
|
||||
else
|
||||
msdWriteTotal += dataLength;
|
||||
|
||||
strcpy(statusLineMsg, "USB Rd:");
|
||||
uint8_t len = write_bytes(statusLineMsg+7, msdReadTotal);
|
||||
strcpy(statusLineMsg+7+len, " Wr:");
|
||||
write_bytes(statusLineMsg+7+len+4, msdWriteTotal);
|
||||
showStatusLine();
|
||||
}
|
||||
|
||||
void usbMassStorage()
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (usbPlugged() && sd_card_ready()) {
|
||||
TRACE_DEBUG("usbMassStorage\n\r");
|
||||
|
||||
if (sdMounted()) {
|
||||
Card_state = SD_ST_DATA;
|
||||
audioQueue.stopSD();
|
||||
logsClose();
|
||||
f_mount(nullptr, "", 0); // unmount SD
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
|
||||
ConfigureUsbClock();
|
||||
|
||||
/* Initialize LUN */
|
||||
MEDSdcard_Initialize(&(medias[DRV_SDMMC]), 0);
|
||||
|
||||
LUN_Init(&(luns[DRV_SDMMC]), &(medias[DRV_SDMMC]),
|
||||
msdBuffer, MSD_BUFFER_SIZE,
|
||||
0, 0, 0, 0,
|
||||
MSDCallbacks_Data);
|
||||
|
||||
/* BOT driver initialization */
|
||||
MSDDriver_Initialize(luns, 1);
|
||||
|
||||
// VBus_Configure();
|
||||
USBD_Connect();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/* Mass storage state machine */
|
||||
for (uint8_t i=0; i<50; i++)
|
||||
MSDDriver_StateMachine();
|
||||
}
|
||||
else {
|
||||
msdReadTotal = 0;
|
||||
msdWriteTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,313 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void setExternalModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTYUPD = GET_MODULE_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
if (GET_MODULE_PPM_POLARITY(EXTERNAL_MODULE))
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void setExtraModulePolarity()
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_MODULE_PPM_DELAY(EXTRA_MODULE) * 2; // Duty in half uS
|
||||
if (GET_MODULE_PPM_POLARITY(EXTRA_MODULE))
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR &= ~0x00000200; // CPOL
|
||||
else
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
|
||||
void module_output_active()
|
||||
{
|
||||
Pio *pioptr = PIOA;
|
||||
pioptr->PIO_ABCDSR[0] &= ~PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_ABCDSR[1] |= PIO_PA17; // Peripheral C
|
||||
pioptr->PIO_PDR = PIO_PA17; // Disable bit A17 Assign to peripheral
|
||||
#if defined(REVX)
|
||||
if (g_model.moduleData[EXTERNAL_MODULE].ppm.outputType) {
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
}
|
||||
else {
|
||||
pioptr->PIO_MDER = PIO_PA17; // Open Drain O/p in A17
|
||||
}
|
||||
#else
|
||||
pioptr->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
pioptr->PIO_PUER = PIO_PA17; // With pull up
|
||||
}
|
||||
|
||||
void init_main_ppm(uint32_t period, uint32_t out_enable)
|
||||
{
|
||||
Pwm * pwmptr;
|
||||
|
||||
if (out_enable) {
|
||||
module_output_active();
|
||||
}
|
||||
|
||||
pwmptr = PWM;
|
||||
// PWM3 for PPM output
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CMR = 0x0004000B; // CLKA
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDR = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CDTY = GET_MODULE_PPM_DELAY(EXTERNAL_MODULE) * 2; // Duty in half uS
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID3; // Enable channel 3
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID3;
|
||||
|
||||
setExternalModulePolarity();
|
||||
|
||||
NVIC_SetPriority(PWM_IRQn, 3);
|
||||
NVIC_EnableIRQ(PWM_IRQn);
|
||||
}
|
||||
|
||||
void disable_main_ppm()
|
||||
{
|
||||
Pio * pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID3;
|
||||
}
|
||||
|
||||
void init_second_ppm(uint32_t period)
|
||||
{
|
||||
// PWM1 for PPM2
|
||||
Pwm * pwmptr = PWM;
|
||||
configure_pins(PIO_PC15, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_NO_PULLUP);
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR = 0x0000000B; // CLKB
|
||||
if (!GET_MODULE_PPM_POLARITY(EXTRA_MODULE)) {
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CMR |= 0x00000200; // CPOL
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDR = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = period; // Period
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTY = GET_MODULE_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_CH_NUM[1].PWM_CDTYUPD = GET_MODULE_PPM_DELAY(EXTRA_MODULE)*2; // Duty
|
||||
pwmptr->PWM_ENA = PWM_ENA_CHID1; // Enable channel 1
|
||||
pwmptr->PWM_IER1 = PWM_IER1_CHID1;
|
||||
|
||||
setExtraModulePolarity();
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO re-add it later
|
||||
void disable_second_ppm()
|
||||
{
|
||||
Pio * pioptr = PIOC;
|
||||
pioptr->PIO_PER = PIO_PC15; // Assign C17 to PIO
|
||||
PWM->PWM_IDR1 = PWM_IDR1_CHID1;
|
||||
}
|
||||
|
||||
void init_module_timer(uint32_t port, uint32_t period, uint8_t state)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
// TODO use period here
|
||||
init_main_ppm(3000, 0);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void extmodulePpmStart()
|
||||
{
|
||||
init_main_ppm(3000, 1);
|
||||
}
|
||||
|
||||
void extramodulePpmStart()
|
||||
{
|
||||
init_second_ppm(3000);
|
||||
}
|
||||
|
||||
// Initialise the SSC to allow PXX output.
|
||||
// TD is on PA17, peripheral A
|
||||
void init_ssc(uint8_t baudrateDiv1000)
|
||||
{
|
||||
Ssc *sscptr;
|
||||
|
||||
PMC->PMC_PCER0 |= 0x00400000L; // Enable peripheral clock to SSC
|
||||
|
||||
configure_pins(PIO_PA17, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA);
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_THR = 0xFF; // Make the output high.
|
||||
sscptr->SSC_TFMR = 0x00000027; // 0000 0000 0000 0000 0000 0000 1010 0111 (8 bit data, lsb)
|
||||
sscptr->SSC_CMR = Master_frequency / (1000 * baudrateDiv1000 * 2);
|
||||
sscptr->SSC_TCMR = 0;
|
||||
sscptr->SSC_CR = SSC_CR_TXEN;
|
||||
|
||||
#if defined(REVX)
|
||||
if (isModuleMultimodule(EXTERNAL_MODULE)) {
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
} else {
|
||||
PIOA->PIO_MDER = PIO_PA17; // Open Drain O/p in A17
|
||||
}
|
||||
#else
|
||||
PIOA->PIO_MDDR = PIO_PA17; // Push Pull O/p in A17
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_ssc()
|
||||
{
|
||||
Pio *pioptr;
|
||||
Ssc *sscptr;
|
||||
|
||||
// Revert back to pwm output
|
||||
pioptr = PIOA;
|
||||
pioptr->PIO_PER = PIO_PA17; // Assign A17 to PIO
|
||||
|
||||
sscptr = SSC;
|
||||
sscptr->SSC_CR = SSC_CR_TXDIS;
|
||||
}
|
||||
|
||||
void extmodulePxx1PulsesStart()
|
||||
{
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125); // 8us per bit
|
||||
}
|
||||
|
||||
void extmoduleStop()
|
||||
{
|
||||
disable_ssc();
|
||||
disable_main_ppm();
|
||||
}
|
||||
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted)
|
||||
{
|
||||
if (baudrate == 125000) {
|
||||
// TODO init_main_ppm could take the period as parameter?
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125);
|
||||
}
|
||||
else {
|
||||
init_main_ppm(3500 * 2, 0);
|
||||
init_ssc(100);
|
||||
}
|
||||
}
|
||||
|
||||
void extmoduleSendNextFrame()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void PWM_IRQHandler(void)
|
||||
{
|
||||
Pwm * pwmptr = PWM;
|
||||
uint32_t reason = pwmptr->PWM_ISR1;
|
||||
uint32_t period;
|
||||
|
||||
if (reason & PWM_ISR1_CHID3) {
|
||||
// Use the current protocol, don't switch until set_up_pulses
|
||||
switch (moduleState[EXTERNAL_MODULE].protocol) {
|
||||
case PROTOCOL_CHANNELS_PXX1_PULSES:
|
||||
// Alternate periods of 6.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 6500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulsesExternalModule();
|
||||
setExternalModulePolarity();
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(extmodulePulsesData.pxx.getData());
|
||||
sscptr->SSC_TCR = extmodulePulsesData.pxx.getSize();
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
case PROTOCOL_CHANNELS_DSM2_LP45:
|
||||
case PROTOCOL_CHANNELS_DSM2_DSM2:
|
||||
case PROTOCOL_CHANNELS_DSM2_DSMX:
|
||||
// Alternate periods of 19.5mS and 2.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 2500 * 2) {
|
||||
period = 19500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 2500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(extmodulePulsesData.dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)extmodulePulsesData.dsm2.ptr - (uint8_t *)extmodulePulsesData.dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTOCOL_CHANNELS_MULTIMODULE:
|
||||
#endif
|
||||
case PROTOCOL_CHANNELS_SBUS:
|
||||
// Todo: how to do inverted polarity on this platform?
|
||||
// Alternate periods of 5.5mS and 3.5 mS
|
||||
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
|
||||
if (period == 3500 * 2) {
|
||||
period = 5500 * 2;
|
||||
}
|
||||
else {
|
||||
period = 3500 * 2;
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 3500 * 2) {
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
else {
|
||||
// Kick off serial output here
|
||||
Ssc * sscptr = SSC;
|
||||
sscptr->SSC_TPR = CONVERT_PTR_UINT(extmodulePulsesData.dsm2.pulses);
|
||||
sscptr->SSC_TCR = (uint8_t *)extmodulePulsesData.dsm2.ptr - (uint8_t *)extmodulePulsesData.dsm2.pulses;
|
||||
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = *extmodulePulsesData.ppm.ptr++;
|
||||
if (*extmodulePulsesData.ppm.ptr == 0) {
|
||||
setExternalModulePolarity();
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (reason & PWM_ISR1_CHID1) {
|
||||
// TODO EXTRA_MODULE will be broken
|
||||
/*pwmptr->PWM_CH_NUM[1].PWM_CPDRUPD = *modulePulsesData[EXTRA_MODULE].ppm.ptr++;
|
||||
if (*modulePulsesData[EXTRA_MODULE].ppm.ptr == 0) {
|
||||
setupPulses(EXTRA_MODULE);
|
||||
setExtraModulePolarity();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
// Configure RF_power (PC17)
|
||||
configure_pins(PIO_PC17, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_NO_PULLUP | PIN_PULLDOWN);
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_INPUT | PIN_PORTA | PIN_PULLUP); // Enable bit A8 (Soft Power)
|
||||
}
|
||||
|
||||
bool pwrPressed()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return true;
|
||||
#else
|
||||
return PIOC->PIO_PDSR & PIO_PC17;
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwrOn()
|
||||
{
|
||||
}
|
||||
|
||||
// turn off soft power
|
||||
void pwrOff()
|
||||
{
|
||||
configure_pins(PIO_PA8, PIN_ENABLE | PIN_OUTPUT | PIN_LOW | PIN_PORTA | PIN_NO_PULLUP);
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
configure_pins(PIO_PC19 | PIO_PC21, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP); // 19 and 21 are rotary encoder
|
||||
configure_pins(PIO_PB6, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP); // rotary encoder switch
|
||||
PIOC->PIO_IER = PIO_PC19 | PIO_PC21;
|
||||
NVIC_EnableIRQ(PIOC_IRQn);
|
||||
}
|
||||
|
||||
void rotaryEncoderEnd()
|
||||
{
|
||||
NVIC_DisableIRQ(PIOC_IRQn);
|
||||
PIOC->PIO_IDR = PIO_PC19 | PIO_PC21;
|
||||
}
|
||||
|
||||
volatile uint32_t Rotary_position;
|
||||
extern "C" void PIOC_IRQHandler()
|
||||
{
|
||||
uint32_t dummy;
|
||||
|
||||
dummy = PIOC->PIO_ISR; // Read and clear status register
|
||||
(void) dummy; // Discard value - prevents compiler warning
|
||||
|
||||
dummy = PIOC->PIO_PDSR; // Read Rotary encoder (PC19, PC21)
|
||||
dummy >>= 19;
|
||||
dummy &= 0x05; // pick out the three bits
|
||||
if (dummy != (Rotary_position & 0x05)) {
|
||||
if ((Rotary_position & 0x01) ^ ((dummy & 0x04) >> 2))
|
||||
rotencValue -= 1;
|
||||
else
|
||||
rotencValue += 1;
|
||||
|
||||
Rotary_position &= ~0x45;
|
||||
Rotary_position |= dummy;
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(REVX)
|
||||
// TODO change this, not the right place
|
||||
#define TWI_NONE 0
|
||||
#define TWI_WRITE_VOL 2
|
||||
#define TWI_WAIT_COMP 7
|
||||
#define TWI_READ_RTC 8
|
||||
#define TWI_WRITE_RTC 9
|
||||
#define TWI_WAIT_RTCSTOP 10
|
||||
#define TWI_WRITE_MFP 11
|
||||
int8_t volumeRequired ;
|
||||
int8_t Rtc_read_pending;
|
||||
uint8_t Rtc_write_pending ;
|
||||
int8_t Rtc_valid ;
|
||||
uint8_t MFPsetting = 0 ;
|
||||
uint8_t CALsetting = 0 ;
|
||||
uint8_t *Twi_read_address ;
|
||||
uint8_t TwiOperation ;
|
||||
#define RTC_RX_BUXSIZE 10
|
||||
#define RTC_SIZE 7
|
||||
uint8_t Rtc_status[RTC_RX_BUXSIZE] ;
|
||||
uint8_t *Rtc_write_ptr ;
|
||||
uint32_t Rtc_write_count ;
|
||||
uint8_t RtcConfig[8] ; // For initial config and writing to RTC
|
||||
// 0x80, 0, 0, 0x08, 0, 0, 0, 0x80
|
||||
|
||||
uint32_t fromBCD(uint8_t bcd_value)
|
||||
{
|
||||
return (((bcd_value & 0xF0) * 10) >> 4) + (bcd_value & 0x0F);
|
||||
}
|
||||
|
||||
uint32_t toBCD(uint32_t value)
|
||||
{
|
||||
div_t qr = div(value, 10);
|
||||
return (qr.quot << 4) + qr.rem;
|
||||
}
|
||||
|
||||
// This is called from an interrupt routine, or
|
||||
// interrupts must be disabled while it is called
|
||||
// from elsewhere.
|
||||
void i2cCheck()
|
||||
{
|
||||
if ( TWI0->TWI_IMR & TWI_IMR_TXCOMP ) {
|
||||
return ; // Busy
|
||||
}
|
||||
|
||||
if ( volumeRequired >= 0 ) // Set volume to this value
|
||||
{
|
||||
TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing
|
||||
TwiOperation = TWI_WRITE_VOL ;
|
||||
TWI0->TWI_THR = volumeRequired ; // Send data
|
||||
volumeRequired = -1 ;
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else if ( Rtc_read_pending )
|
||||
{
|
||||
Rtc_valid = 0 ;
|
||||
Rtc_read_pending = 0 ;
|
||||
TWI0->TWI_MMR = 0x006F1100 ; // Device 6F and master is reading, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_READ_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_RPR = (uint32_t)&Rtc_status[0] ;
|
||||
#endif
|
||||
TWI0->TWI_RCR = RTC_SIZE - 1 ;
|
||||
if ( TWI0->TWI_SR & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ;
|
||||
}
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTEN ; // Start transfers
|
||||
TWI0->TWI_CR = TWI_CR_START ; // Start Rx
|
||||
TWI0->TWI_IER = TWI_IER_RXBUFF | TWI_IER_TXCOMP ;
|
||||
}
|
||||
else if ( Rtc_write_pending )
|
||||
{
|
||||
if ( Rtc_write_pending & (2|4) )
|
||||
{
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TwiOperation = TWI_WRITE_MFP ;
|
||||
if ( Rtc_write_pending & 2 )
|
||||
{
|
||||
TWI0->TWI_IADR = 7 ;
|
||||
TWI0->TWI_THR = MFPsetting ; // Send data
|
||||
Rtc_write_pending &= ~2 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
TWI0->TWI_IADR = 8 ;
|
||||
TWI0->TWI_THR = CALsetting ; // Send data
|
||||
Rtc_write_pending &= ~4 ;
|
||||
}
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
else
|
||||
{
|
||||
Rtc_write_pending &= ~1 ;
|
||||
TWI0->TWI_MMR = 0x006F0100 ; // Device 6F and master is writing, 1 byte addr
|
||||
TWI0->TWI_IADR = 0 ;
|
||||
TwiOperation = TWI_WRITE_RTC ;
|
||||
#ifndef SIMU
|
||||
TWI0->TWI_TPR = (uint32_t)Rtc_write_ptr+1 ;
|
||||
#endif
|
||||
TWI0->TWI_TCR = Rtc_write_count-1 ;
|
||||
TWI0->TWI_THR = *Rtc_write_ptr ; // First byte
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTEN ; // Start data transfer
|
||||
TWI0->TWI_IER = TWI_IER_TXBUFE | TWI_IER_TXCOMP ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeRTC(uint8_t *ptr)
|
||||
{
|
||||
uint32_t year;
|
||||
RtcConfig[0] = 0x80 | toBCD(*ptr++);
|
||||
RtcConfig[1] = toBCD(*ptr++);
|
||||
RtcConfig[2] = toBCD(*ptr++);
|
||||
RtcConfig[3] = 0x08;
|
||||
RtcConfig[4] = toBCD(*ptr++);
|
||||
RtcConfig[5] = toBCD( *ptr++);
|
||||
year = *ptr++;
|
||||
year |= *ptr << 8;
|
||||
RtcConfig[6] = toBCD(year - 2000);
|
||||
RtcConfig[7] = MFPsetting;
|
||||
Rtc_write_ptr = RtcConfig;
|
||||
Rtc_write_count = 8;
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 1;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void readRTC()
|
||||
{
|
||||
Rtc_read_pending = 1 ;
|
||||
__disable_irq() ;
|
||||
i2cCheck() ;
|
||||
__enable_irq() ;
|
||||
}
|
||||
|
||||
// TODO should be inside an i2c_driver.cpp
|
||||
#ifndef SIMU
|
||||
extern "C" void TWI0_IRQHandler()
|
||||
{
|
||||
uint32_t status ;
|
||||
status = TWI0->TWI_SR ; // Read only once, some bits cleared on read
|
||||
|
||||
if ( TwiOperation == TWI_READ_RTC )
|
||||
{
|
||||
if ( status & TWI_SR_RXBUFF )
|
||||
{
|
||||
TWI0->TWI_IDR = TWI_IDR_RXBUFF ;
|
||||
TwiOperation = TWI_WAIT_RTCSTOP ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
TWI0->TWI_RCR = 1 ; // Last byte
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// must be TXCOMP, prob. NAK in data
|
||||
if ( TWI0->TWI_RCR > 0 )
|
||||
{
|
||||
Rtc_valid = -1 ;
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Rx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( TwiOperation == TWI_WAIT_RTCSTOP )
|
||||
{
|
||||
Rtc_valid = 1 ;
|
||||
// Set the date and time
|
||||
struct gtm utm;
|
||||
|
||||
utm.tm_sec = fromBCD( Rtc_status[0] & 0x7F ) ;
|
||||
utm.tm_min = fromBCD( Rtc_status[1] & 0x7F ) ;
|
||||
utm.tm_hour = fromBCD( Rtc_status[2] & 0x3F ) ;
|
||||
utm.tm_mday = fromBCD( Rtc_status[4] & 0x3F ) ;
|
||||
utm.tm_mon = fromBCD( Rtc_status[5] & 0x1F ) - 1;
|
||||
utm.tm_year = fromBCD( Rtc_status[6] ) + 100 ;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
|
||||
TWI0->TWI_PTCR = TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( status & TWI_SR_RXRDY )
|
||||
{
|
||||
(void) TWI0->TWI_RHR ; // Discard any rubbish data
|
||||
}
|
||||
}
|
||||
|
||||
if ( status & TWI_SR_NACK )
|
||||
{
|
||||
TWI0->TWI_CR = TWI_CR_STOP ; // Stop Tx
|
||||
}
|
||||
|
||||
TWI0->TWI_IDR = TWI_IDR_TXCOMP | TWI_IDR_TXBUFE | TWI_IDR_RXBUFF ;
|
||||
TWI0->TWI_PTCR = TWI_PTCR_TXTDIS | TWI_PTCR_RXTDIS ; // Stop transfers
|
||||
if ( ( status & TWI_SR_TXCOMP ) == 0 )
|
||||
{
|
||||
TWI0->TWI_IER = TWI_IER_TXCOMP ;
|
||||
TwiOperation = TWI_WAIT_COMP ;
|
||||
return ;
|
||||
}
|
||||
|
||||
TwiOperation = TWI_NONE ;
|
||||
i2cCheck() ;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct t_i2cTime
|
||||
{
|
||||
uint8_t setCode ;
|
||||
uint8_t Time[7] ;
|
||||
} I2CTime ;
|
||||
|
||||
void rtcSetTime(const struct gtm * t)
|
||||
{
|
||||
g_ms100 = 0; // start of next second begins now
|
||||
|
||||
I2CTime.setCode = 0x74 ; // Tiny SET TIME CODE command
|
||||
I2CTime.Time[0] = t->tm_sec ;
|
||||
I2CTime.Time[1] = t->tm_min ;
|
||||
I2CTime.Time[2] = t->tm_hour ;
|
||||
I2CTime.Time[3] = t->tm_mday ;
|
||||
I2CTime.Time[4] = t->tm_mon+1 ;
|
||||
I2CTime.Time[5] = (uint8_t) (t->tm_year+TM_YEAR_BASE);
|
||||
I2CTime.Time[6] = (t->tm_year+TM_YEAR_BASE) >> 8;
|
||||
#if defined(REVX)
|
||||
writeRTC((uint8_t *)&I2CTime.Time[0]) ;
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocWriteData((uint8_t *) &I2CTime, 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtcInit()
|
||||
{
|
||||
#if defined(REVX)
|
||||
readRTC();
|
||||
#elif defined(COPROCESSOR)
|
||||
coprocReadData();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(REVX)
|
||||
void writeMFP()
|
||||
{
|
||||
__disable_irq();
|
||||
Rtc_write_pending |= 2;
|
||||
i2cCheck();
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void setMFP()
|
||||
{
|
||||
MFPsetting = 0x80;
|
||||
writeMFP();
|
||||
}
|
||||
|
||||
void clearMFP()
|
||||
{
|
||||
MFPsetting = 0;
|
||||
writeMFP();
|
||||
}
|
||||
#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "i2c_driver.h"
|
||||
|
||||
#define DS3231_I2C_CHIPID 0x68
|
||||
|
||||
void readRtc()
|
||||
{
|
||||
uint8_t buffer[7];
|
||||
uint8_t address[]= {0};
|
||||
gtm utm;
|
||||
int res = i2cReadBuffer(DS3231_I2C_CHIPID, address, 1, buffer, 7);
|
||||
if (res != 0)
|
||||
return;
|
||||
|
||||
// Set the date and time
|
||||
utm.tm_sec = fromBCD(buffer[0] & 0x7F);
|
||||
utm.tm_min = fromBCD(buffer[1] & 0x7F);
|
||||
utm.tm_hour = fromBCD(buffer[2] & 0x3F);
|
||||
utm.tm_mday = fromBCD(buffer[4] & 0x3F);
|
||||
utm.tm_mon = fromBCD(buffer[5] & 0x1F) - 1;
|
||||
utm.tm_year = fromBCD(buffer[6]) + 100;
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
|
||||
void writeRtc(const gtm* ptr)
|
||||
{
|
||||
g_ms100 = 0; // start of next second begins now
|
||||
uint8_t buffer[7];
|
||||
uint8_t address[]= {0};
|
||||
|
||||
buffer[0] = toBCD(ptr->tm_sec);
|
||||
buffer[1] = toBCD(ptr->tm_min);
|
||||
buffer[2] = toBCD(ptr->tm_hour);
|
||||
buffer[3] = toBCD(ptr->tm_wday);
|
||||
buffer[4] = toBCD(ptr->tm_mday);
|
||||
buffer[5] = toBCD(ptr->tm_mon + 1);
|
||||
uint8_t offset = ptr->tm_year >= 100 ? 100 : 0;
|
||||
buffer[6] = toBCD(ptr->tm_year - offset);
|
||||
i2cWriteBuffer(DS3231_I2C_CHIPID, address, 1, buffer, 7);
|
||||
}
|
||||
|
||||
void rtcSetTime(const struct gtm * t)
|
||||
{
|
||||
writeRtc(t);
|
||||
}
|
||||
|
||||
void rtcInit()
|
||||
{
|
||||
readRtc();
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 256K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
KEEP(*(.bootloader)) /* Bootloader code */
|
||||
|
||||
. = 0x8000; /* Set the start of the main program */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
.ARM.extab : {
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > FLASH
|
||||
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} > FLASH
|
||||
|
||||
_sidata = .;
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_sidata)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2011 by Michael Fischer. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
* History:
|
||||
*
|
||||
* 22.05.2011 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* In this linker script there is no heap available.
|
||||
* The stack start at the end of the ram segment.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Take a look in the "The GNU linker" manual, here you get
|
||||
* the following information about the "MEMORY":
|
||||
*
|
||||
* "The MEMORY command describes the location and size of
|
||||
* blocks of memory in the target."
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00400000, LENGTH = 512K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* And the "SECTION" is used for:
|
||||
*
|
||||
* "The SECTIONS command tells the linker how to map input
|
||||
* sections into output sections, and how to place the output
|
||||
* sections in memory.
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/*
|
||||
* The ".text" section is used for the code, and
|
||||
* read only (.rodata) data. Even the vectors (.vectors)
|
||||
* MUST be saved at the start of this section.
|
||||
*/
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
KEEP(*(.bootloader)) /* Bootloader code */
|
||||
|
||||
. = 0x8000; /* Set the start of the main program */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
|
||||
KEEP(*(.vectors))
|
||||
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the rodata part */
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > FLASH = 0
|
||||
_etext = .; /* Provide the name for the end of this section */
|
||||
|
||||
.ARM.extab : {
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > FLASH
|
||||
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} > FLASH
|
||||
|
||||
_sidata = .;
|
||||
|
||||
/*
|
||||
* The ".data" section is used for initialized data
|
||||
* and for functions (.fastrun) which should be copied
|
||||
* from flash to ram. This functions will later be
|
||||
* executed from ram instead of flash.
|
||||
*/
|
||||
.data : AT (_sidata)
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sdata = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4); /* Align the start of the fastrun part */
|
||||
*(.fastrun)
|
||||
*(.fastrun.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_edata = .; /* Provide the name for the end of this section */
|
||||
|
||||
/*
|
||||
* The ".bss" section is used for uninitialized data.
|
||||
* This section will be cleared by the startup code.
|
||||
*/
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4); /* Align the start of the section */
|
||||
_sbss = .; /* Provide the name for the start of this section */
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
} > RAM
|
||||
_ebss = .; /* Provide the name for the end of this section */
|
||||
|
||||
. = ALIGN(4); /* Align the end of the section */
|
||||
__end = .;
|
||||
_end = .;
|
||||
|
||||
/*
|
||||
* The ".stack" section is our stack.
|
||||
* Here this section starts at the end of the ram segment.
|
||||
*/
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
}
|
||||
|
||||
/*** EOF **/
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define MCI_INITIAL_SPEED 400000
|
||||
|
||||
void init_SDcard()
|
||||
{
|
||||
#ifndef SIMU
|
||||
configure_pins( 0xFC000000, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_C | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
configure_pins( PIO_PB7, PIN_INPUT | PIN_PORTB | PIN_NO_PULLUP | PIN_NO_PULLDOWN ) ;
|
||||
|
||||
unsigned short clkDiv;
|
||||
Hsmci *pMciHw = HSMCI ;
|
||||
|
||||
/* Enable the MCI peripheral */
|
||||
PMC->PMC_PCER0 |= 1 << ID_HSMCI ; // Enable peripheral clock to HSMCI
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_SWRST; /* Reset the MCI */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIDIS | HSMCI_CR_PWSDIS; /* Disable the MCI */
|
||||
pMciHw->HSMCI_IDR = 0xFFFFFFFF; /* Disable all the interrupts */
|
||||
pMciHw->HSMCI_DTOR = HSMCI_DTOR_DTOCYC_Msk | HSMCI_DTOR_DTOMUL_Msk ; /* Set the Data Timeout Register */
|
||||
pMciHw->HSMCI_CSTOR = HSMCI_CSTOR_CSTOCYC_Msk | HSMCI_CSTOR_CSTOMUL_Msk ; /* CSTOR ? */
|
||||
/* Set the Mode Register: 400KHz for MCK = 48MHz (CLKDIV = 58) */
|
||||
clkDiv = 45; // (Master_frequency / (MCI_INITIAL_SPEED * 2)) - 1;
|
||||
pMciHw->HSMCI_MR = clkDiv | (7 << 8) ;
|
||||
|
||||
/* Set the SDCard Register 1-bit, slot A */
|
||||
pMciHw->HSMCI_SDCR = HSMCI_SDCR_SDCSEL_SLOTA | HSMCI_SDCR_SDCBUS_1 ;
|
||||
/* Enable the MCI and the Power Saving */
|
||||
pMciHw->HSMCI_CR = HSMCI_CR_MCIEN/* | HSMCI_CR_PWSEN */;
|
||||
/* Configure MCI */
|
||||
pMciHw->HSMCI_CFG = HSMCI_CFG_FIFOMODE | HSMCI_CFG_FERRCTRL;
|
||||
#endif
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define RX_UART_BUFFER_SIZE 128
|
||||
|
||||
struct t_rxUartBuffer
|
||||
{
|
||||
uint8_t fifo[RX_UART_BUFFER_SIZE] ;
|
||||
uint8_t *outPtr ;
|
||||
};
|
||||
|
||||
struct t_rxUartBuffer TelemetryInBuffer ;
|
||||
uint16_t DsmRxTimeout;
|
||||
|
||||
// USART0 configuration
|
||||
// Work in Progress, UNTESTED
|
||||
// Uses PA5 and PA6 (RXD and TXD)
|
||||
void UART2_Configure(uint32_t baudrate, uint32_t masterClock, int mode)
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
|
||||
// Configure PIO
|
||||
configure_pins( (PIO_PA5 | PIO_PA6), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
|
||||
|
||||
// Configure PMC
|
||||
PMC->PMC_PCER0 = 1 << SECOND_ID;
|
||||
|
||||
// Reset and disable receiver & transmitter */
|
||||
pUsart->US_CR = US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS;
|
||||
|
||||
// Configure mode
|
||||
if (mode & TELEMETRY_SERIAL_8E2)
|
||||
pUsart->US_MR = 0x000020C0 ;
|
||||
else
|
||||
pUsart->US_MR = 0x000008C0 ; // NORMAL, No Parity, 8 bit
|
||||
|
||||
// Configure baudrate
|
||||
// Asynchronous, no oversampling
|
||||
pUsart->US_BRGR = (masterClock / baudrate) / 16;
|
||||
|
||||
// Disable PDC channel
|
||||
pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS;
|
||||
|
||||
// Enable receiver and transmitter
|
||||
pUsart->US_CR = US_CR_RXEN | US_CR_TXEN;
|
||||
}
|
||||
|
||||
void UART2_timeout_enable()
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
pUsart->US_CR = US_CR_STTTO ;
|
||||
pUsart->US_RTOR = 115 ; // Bits @ 115200 ~= 1mS
|
||||
pUsart->US_IER = US_IER_TIMEOUT ;
|
||||
DsmRxTimeout = 0 ;
|
||||
NVIC_EnableIRQ(USART0_IRQn);
|
||||
}
|
||||
|
||||
void UART2_timeout_disable()
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
pUsart->US_RTOR = 0 ;
|
||||
pUsart->US_IDR = US_IDR_TIMEOUT ;
|
||||
NVIC_DisableIRQ(USART0_IRQn);
|
||||
}
|
||||
|
||||
extern "C" void USART0_IRQHandler()
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
pUsart->US_CR = US_CR_STTTO ; // Clears timeout bit
|
||||
DsmRxTimeout = 1;
|
||||
}
|
||||
|
||||
void startPdcUsartReceive()
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
TelemetryInBuffer.outPtr = TelemetryInBuffer.fifo ;
|
||||
pUsart->US_RPR = (uint32_t)TelemetryInBuffer.fifo ;
|
||||
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer.fifo ;
|
||||
pUsart->US_RCR = RX_UART_BUFFER_SIZE ;
|
||||
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
|
||||
pUsart->US_PTCR = US_PTCR_RXTEN ;
|
||||
}
|
||||
|
||||
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
uint8_t *ptr ;
|
||||
uint8_t *endPtr ;
|
||||
|
||||
// Find out where the DMA has got to
|
||||
endPtr = (uint8_t *)pUsart->US_RPR ;
|
||||
// Check for DMA passed end of buffer
|
||||
if ( endPtr > &TelemetryInBuffer.fifo[RX_UART_BUFFER_SIZE-1] )
|
||||
{
|
||||
endPtr = TelemetryInBuffer.fifo ;
|
||||
}
|
||||
ptr = TelemetryInBuffer.outPtr ;
|
||||
while ( ptr != endPtr )
|
||||
{
|
||||
(*pChProcess)(*ptr++) ;
|
||||
if ( ptr > &TelemetryInBuffer.fifo[RX_UART_BUFFER_SIZE-1] ) // last byte
|
||||
{
|
||||
ptr = TelemetryInBuffer.fifo ;
|
||||
}
|
||||
}
|
||||
TelemetryInBuffer.outPtr = ptr ;
|
||||
|
||||
if ( pUsart->US_RNCR == 0 )
|
||||
{
|
||||
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer.fifo ;
|
||||
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t txPdcUsart(const uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
Usart * pUsart = SECOND_USART;
|
||||
|
||||
if (pUsart->US_TNCR == 0) {
|
||||
pUsart->US_TNPR = (uint32_t)buffer ;
|
||||
pUsart->US_TNCR = size ;
|
||||
pUsart->US_PTCR = US_PTCR_TXTEN ;
|
||||
return 1 ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
uint32_t telemetryTransmitPending()
|
||||
{
|
||||
Usart *pUsart = SECOND_USART;
|
||||
uint32_t x ;
|
||||
|
||||
__disable_irq() ;
|
||||
pUsart->US_PTCR = US_PTCR_TXTDIS ; // Freeze DMA
|
||||
x = pUsart->US_TNCR ; // Total
|
||||
x += pUsart->US_TCR ; // Still to send
|
||||
pUsart->US_PTCR = US_PTCR_TXTEN ; // DMA active again
|
||||
__enable_irq() ;
|
||||
|
||||
return x ;
|
||||
}
|
||||
*/
|
||||
|
||||
void telemetryPortSetDirectionOutput()
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortSetDirectionInput()
|
||||
{
|
||||
}
|
||||
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
{
|
||||
UART2_Configure(baudrate, Master_frequency, mode);
|
||||
startPdcUsartReceive();
|
||||
}
|
||||
|
||||
void sportSendBuffer(const uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
telemetryTransmitBuffer(buffer, size);
|
||||
}
|
||||
|
||||
void telemetryTransmitBuffer(const uint8_t * buffer, uint32_t size)
|
||||
{
|
||||
txPdcUsart(buffer, size);
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
// Start TIMER3 for input capture
|
||||
inline void start_timer3()
|
||||
{
|
||||
Tc *ptc ;
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x04000000L ; // Enable peripheral clock to TC3
|
||||
|
||||
ptc = TC1 ; // Tc block 1 (TC3-5)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 2 ;
|
||||
ptc->TC_CHANNEL[0].TC_CMR = 0x00000000 ; // Capture mode
|
||||
ptc->TC_CHANNEL[0].TC_CMR = 0x00090005 ; // 0000 0000 0000 1001 0000 0000 0000 0101, XC0, A rise, b fall
|
||||
ptc->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
|
||||
configure_pins( PIO_PC23, PIN_PERIPHERAL | PIN_INPUT | PIN_PER_B | PIN_PORTC | PIN_PULLUP ) ;
|
||||
|
||||
NVIC_SetPriority( TC3_IRQn, 14 ) ; // Low priority interrupt
|
||||
NVIC_EnableIRQ(TC3_IRQn) ;
|
||||
ptc->TC_CHANNEL[0].TC_IER = TC_IER0_LDRAS ;
|
||||
}
|
||||
|
||||
// Start Timer4 to provide 0.5uS clock for input capture
|
||||
void start_timer4()
|
||||
{
|
||||
Tc *ptc ;
|
||||
uint32_t timer ;
|
||||
|
||||
timer = Master_frequency / (2*2000000) ; // MCK/2 and 2MHz
|
||||
|
||||
// Enable peripheral clock TC0 = bit 23 thru TC5 = bit 28
|
||||
PMC->PMC_PCER0 |= 0x08000000L ; // Enable peripheral clock to TC4
|
||||
|
||||
ptc = TC1 ; // Tc block 1 (TC3-5)
|
||||
ptc->TC_BCR = 0 ; // No sync
|
||||
ptc->TC_BMR = 0 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x00008000 ; // Waveform mode
|
||||
ptc->TC_CHANNEL[1].TC_RC = timer ;
|
||||
ptc->TC_CHANNEL[1].TC_RA = timer >> 1 ;
|
||||
ptc->TC_CHANNEL[1].TC_CMR = 0x0009C000 ; // 0000 0000 0000 1001 1100 0000 0100 0000
|
||||
// MCK/2, set @ RA, Clear @ RC waveform
|
||||
ptc->TC_CHANNEL[1].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger)
|
||||
}
|
||||
|
||||
// Timer3 used for PPM_IN pulse width capture. Counter running at 16MHz / 8 = 2MHz
|
||||
// equating to one count every half millisecond. (2 counts = 1ms). Control channel
|
||||
// count delta values thus can range from about 1600 to 4400 counts (800us to 2200us),
|
||||
// corresponding to a PPM signal in the range 0.8ms to 2.2ms (1.5ms at center).
|
||||
// (The timer is free-running and is thus not reset to zero at each capture interval.)
|
||||
// Timer 4 generates the 2MHz clock to clock Timer 3
|
||||
|
||||
extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz
|
||||
{
|
||||
uint32_t status = TC1->TC_CHANNEL[0].TC_SR;
|
||||
if (status & TC_SR0_LDRAS) {
|
||||
uint16_t capture = TC1->TC_CHANNEL[0].TC_RA ;
|
||||
captureTrainerPulses(capture);
|
||||
}
|
||||
}
|
||||
|
||||
void init_trainer_capture()
|
||||
{
|
||||
PIOC->PIO_PER = PIO_PC22;
|
||||
start_timer4() ;
|
||||
start_timer3() ;
|
||||
}
|
||||
|
||||
void stop_trainer_capture()
|
||||
{
|
||||
PIOC->PIO_PDR = PIO_PC22;
|
||||
TC1->TC_CHANNEL[0].TC_IDR = TC_IDR0_LDRAS ;
|
||||
NVIC_DisableIRQ(TC3_IRQn) ;
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBConfigurationDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBConfigurationDescriptor class.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBConfigurationDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the total length of a configuration, i.e. including the
|
||||
/// descriptors following it.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Total length (in bytes) of the configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->wTotalLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the number of interfaces in a configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return Number of interfaces in configuration.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
return configuration->bNumInterfaces;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Indicates if the device is self-powered when in a given configuration.
|
||||
/// \param configuration Pointer to a USBConfigurationDescriptor instance.
|
||||
/// \return 1 if the device is self-powered when in the given configuration;
|
||||
/// otherwise 0.
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration)
|
||||
{
|
||||
if ((configuration->bmAttributes & (1 << 6)) != 0) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Parses the given Configuration descriptor (followed by relevant
|
||||
/// interface, endpoint and class-specific descriptors) into three arrays.
|
||||
/// *Each array must have its size equal or greater to the number of
|
||||
/// descriptors it stores plus one*. A null-value is inserted after the last
|
||||
/// descriptor of each type to indicate the array end.
|
||||
///
|
||||
/// Note that if the pointer to an array is null (0), nothing is stored in
|
||||
/// it.
|
||||
/// \param configuration Pointer to the start of the whole Configuration
|
||||
/// descriptor.
|
||||
/// \param interfaces Pointer to the Interface descriptor array.
|
||||
/// \param endpoints Pointer to the Endpoint descriptor array.
|
||||
/// \param others Pointer to the class-specific descriptor array.
|
||||
//-----------------------------------------------------------------------------
|
||||
void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others)
|
||||
{
|
||||
// Get size of configuration to parse
|
||||
int size = USBConfigurationDescriptor_GetTotalLength(configuration);
|
||||
size -= sizeof(USBConfigurationDescriptor);
|
||||
|
||||
// Start parsing descriptors
|
||||
USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
|
||||
while (size > 0) {
|
||||
|
||||
// Get next descriptor
|
||||
descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
|
||||
size -= USBGenericDescriptor_GetLength(descriptor);
|
||||
|
||||
// Store descriptor in correponding array
|
||||
if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_INTERFACE) {
|
||||
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = (USBInterfaceDescriptor *) descriptor;
|
||||
interfaces++;
|
||||
}
|
||||
}
|
||||
else if (USBGenericDescriptor_GetType(descriptor)
|
||||
== USBGenericDescriptor_ENDPOINT) {
|
||||
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = (USBEndpointDescriptor *) descriptor;
|
||||
endpoints++;
|
||||
}
|
||||
}
|
||||
else if (others) {
|
||||
|
||||
*others = descriptor;
|
||||
others++;
|
||||
}
|
||||
}
|
||||
|
||||
// Null-terminate arrays
|
||||
if (interfaces) {
|
||||
|
||||
*interfaces = 0;
|
||||
}
|
||||
if (endpoints) {
|
||||
|
||||
*endpoints = 0;
|
||||
}
|
||||
if (others) {
|
||||
|
||||
*others = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Definitions and methods for USB configuration descriptor structures
|
||||
described by the USB specification.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBConfigurationDescriptor instance as a part
|
||||
of the configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
configuration descriptor, use
|
||||
- USBConfigurationDescriptor_GetTotalLength
|
||||
- USBConfigurationDescriptor_GetNumInterfaces
|
||||
- USBConfigurationDescriptor_IsSelfPowered
|
||||
-# To pase the defined USB device configuration descriptor, use
|
||||
- USBConfigurationDescriptor_Parse
|
||||
*/
|
||||
|
||||
#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
#define USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Headers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
#include "../../../usb/common/core/USBInterfaceDescriptor.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// \page "USB device Attributes"
|
||||
///
|
||||
/// This page lists the codes of the usb attributes.
|
||||
///
|
||||
/// !Attributes
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
|
||||
/// - USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
|
||||
/// - USBConfigurationDescriptor_POWER
|
||||
|
||||
/// Device is bus-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
|
||||
/// Device is self-powered and not support remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
|
||||
/// Device is bus-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
|
||||
/// Device is self-powered and supports remote wake-up.
|
||||
#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
|
||||
|
||||
/// Calculates the value of the power consumption field given the value in mA.
|
||||
/// \param power The power consumption value in mA
|
||||
/// \return The value that should be set to the field in descriptor
|
||||
#define USBConfigurationDescriptor_POWER(power) (power / 2)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// USB standard configuration descriptor structure.
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_CONFIGURATION of "USB Descriptor types").
|
||||
unsigned char bDescriptorType;
|
||||
/// Length of all descriptors returned along with this configuration
|
||||
/// descriptor.
|
||||
unsigned short wTotalLength;
|
||||
/// Number of interfaces in this configuration.
|
||||
unsigned char bNumInterfaces;
|
||||
/// Value for selecting this configuration.
|
||||
unsigned char bConfigurationValue;
|
||||
/// Index of the configuration string descriptor.
|
||||
unsigned char iConfiguration;
|
||||
/// Configuration characteristics.
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum power consumption of the device when in this configuration.
|
||||
unsigned char bMaxPower;
|
||||
|
||||
} __attribute__ ((packed)) USBConfigurationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBConfigurationDescriptor_GetTotalLength(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_GetNumInterfaces(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern unsigned char USBConfigurationDescriptor_IsSelfPowered(
|
||||
const USBConfigurationDescriptor *configuration);
|
||||
|
||||
extern void USBConfigurationDescriptor_Parse(
|
||||
const USBConfigurationDescriptor *configuration,
|
||||
USBInterfaceDescriptor **interfaces,
|
||||
USBEndpointDescriptor **endpoints,
|
||||
USBGenericDescriptor **others);
|
||||
|
||||
#endif //#ifndef USBCONFIGURATIONDESCRIPTOR_H
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceDescriptor instance as the device descriptor of a
|
||||
USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEDESCRIPTOR_H
|
||||
#define USBDEVICEDESCRIPTOR_H
|
||||
|
||||
#include "board_lowlevel.h"
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB release numbers"
|
||||
///
|
||||
/// This page lists the codes of USB release numbers.
|
||||
///
|
||||
/// !Code
|
||||
/// - USBDeviceDescriptor_USB2_00
|
||||
|
||||
/// The device supports USB 2.00.
|
||||
#define USBDeviceDescriptor_USB2_00 0x0200
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard device descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_DEVICE).
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number in BCD format.
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0 (in bytes).
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Vendor ID.
|
||||
unsigned short idVendor;
|
||||
/// Product ID.
|
||||
unsigned short idProduct;
|
||||
/// Device release number in BCD format.
|
||||
unsigned short bcdDevice;
|
||||
/// Index of the manufacturer string descriptor.
|
||||
unsigned char iManufacturer;
|
||||
/// Index of the product string descriptor.
|
||||
unsigned char iProduct;
|
||||
/// Index of the serial number string descriptor.
|
||||
unsigned char iSerialNumber;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceDescriptor; // GCC
|
||||
|
||||
#if defined(CHIP_USB_OTGHS)
|
||||
typedef struct {
|
||||
|
||||
/// Size of this descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_OTG).
|
||||
unsigned char bDescriptorType;
|
||||
/// Attribute Fields D7�2: Reserved D1: HNP support D0: SRP support
|
||||
unsigned char bmAttributes;
|
||||
|
||||
} __attribute__ ((packed)) USBOtgDescriptor; // GCC
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEDESCRIPTOR_H
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Class for manipulating USB device qualifier descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare a USBDeviceQualifierDescriptor instance as the device qualifier
|
||||
descriptor of a USB device.
|
||||
*/
|
||||
|
||||
#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
#define USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Alternate device descriptor indicating the capabilities of the device
|
||||
/// in full-speed, if currently in high-speed; or in high-speed, if it is
|
||||
/// currently in full-speed. Only relevant for devices supporting the
|
||||
/// high-speed mode.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types").
|
||||
unsigned char bDescriptorType;
|
||||
/// USB specification release number (in BCD format).
|
||||
unsigned short bcdUSB;
|
||||
/// Device class code.
|
||||
unsigned char bDeviceClass;
|
||||
/// Device subclass code.
|
||||
unsigned char bDeviceSubClass;
|
||||
/// Device protocol code.
|
||||
unsigned char bDeviceProtocol;
|
||||
/// Maximum packet size of endpoint 0.
|
||||
unsigned char bMaxPacketSize0;
|
||||
/// Number of possible configurations for the device.
|
||||
unsigned char bNumConfigurations;
|
||||
/// Reserved.
|
||||
unsigned char bReserved;
|
||||
|
||||
} __attribute__ ((packed)) USBDeviceQualifierDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBEndpointDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBEndpointDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBEndpointDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the number of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bEndpointAddress & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint direction (see <Endpoint directions>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
if ((endpoint->bEndpointAddress & 0x80) != 0) {
|
||||
|
||||
return USBEndpointDescriptor_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBEndpointDescriptor_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of an endpoint given its descriptor.
|
||||
/// \param endpoint Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Endpoint type (see <Endpoint types>).
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bmAttributes & 0x3;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the maximum size of a packet (in bytes) on an endpoint given
|
||||
/// its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Maximum packet size of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->wMaxPacketSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the polling interval on an endpoint given its descriptor.
|
||||
/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
|
||||
/// \return Polling interval of endpoint.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint)
|
||||
{
|
||||
return endpoint->bInterval;
|
||||
}
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for handling USB endpoint descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare USBEndpointDescriptor instance as a part of the
|
||||
configuration descriptors of a USB device.
|
||||
-# To get useful information (field values) from the defined USB device
|
||||
endpoint descriptor (to configure hardware for endpoints, etc), use
|
||||
- USBEndpointDescriptor_GetNumber
|
||||
- USBEndpointDescriptor_GetDirection
|
||||
- USBEndpointDescriptor_GetType
|
||||
- USBEndpointDescriptor_GetMaxPacketSize
|
||||
*/
|
||||
|
||||
#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
#define USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint definitions"
|
||||
///
|
||||
/// This page lists definitions and macro for endpoint descriptors.
|
||||
///
|
||||
/// - USB Endpoint directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
///
|
||||
/// - USB Endpoint types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
///
|
||||
/// - USB Endpoint maximun sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
///
|
||||
/// - USB Endpoint address define
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint directions"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBEndpointDescriptor_OUT
|
||||
/// - USBEndpointDescriptor_IN
|
||||
|
||||
/// Endpoint receives data from the host.
|
||||
#define USBEndpointDescriptor_OUT 0
|
||||
/// Endpoint sends data to the host.
|
||||
#define USBEndpointDescriptor_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint types"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBEndpointDescriptor_CONTROL
|
||||
/// - USBEndpointDescriptor_ISOCHRONOUS
|
||||
/// - USBEndpointDescriptor_BULK
|
||||
/// - USBEndpointDescriptor_INTERRUPT
|
||||
|
||||
/// Control endpoint type.
|
||||
#define USBEndpointDescriptor_CONTROL 0
|
||||
/// Isochronous endpoint type.
|
||||
#define USBEndpointDescriptor_ISOCHRONOUS 1
|
||||
/// Bulk endpoint type.
|
||||
#define USBEndpointDescriptor_BULK 2
|
||||
/// Interrupt endpoint type.
|
||||
#define USBEndpointDescriptor_INTERRUPT 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint maximun sizes"
|
||||
///
|
||||
/// This page lists definitions of USB endpoint maximun sizes.
|
||||
///
|
||||
/// !Sizes
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXBULKSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
|
||||
/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
|
||||
|
||||
/// Maximum size for a full-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
|
||||
/// Maximum size for a high-speed control endpoint.
|
||||
#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
|
||||
/// Maximum size for a full-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
|
||||
/// Maximum size for a high-speed bulk endpoint.
|
||||
#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
|
||||
/// Maximum size for a full-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
|
||||
/// Maximum size for a high-speed interrupt endpoint.
|
||||
#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
|
||||
/// Maximum size for a full-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
|
||||
/// Maximum size for a high-speed isochronous endpoint.
|
||||
#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Endpoint address define"
|
||||
///
|
||||
/// This page lists macro for USB endpoint address definition.
|
||||
///
|
||||
/// !Macro
|
||||
/// - USBEndpointDescriptor_ADDRESS
|
||||
|
||||
/// Calculates the address of an endpoint given its number and direction
|
||||
/// \param direction USB endpoint direction definition
|
||||
/// \param number USB endpoint number
|
||||
/// \return The value used to set the endpoint descriptor based on input number
|
||||
/// and direction
|
||||
#define USBEndpointDescriptor_ADDRESS(direction, number) \
|
||||
(((direction & 0x01) << 7) | (number & 0xF))
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard endpoint descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (<USBGenericDescriptor_ENDPOINT>).
|
||||
unsigned char bDescriptorType;
|
||||
/// Address and direction of the endpoint.
|
||||
unsigned char bEndpointAddress;
|
||||
/// Endpoint type and additional characteristics (for isochronous endpoints).
|
||||
unsigned char bmAttributes;
|
||||
/// Maximum packet size (in bytes) of the endpoint.
|
||||
unsigned short wMaxPacketSize;
|
||||
/// Polling rate of the endpoint.
|
||||
unsigned char bInterval;
|
||||
|
||||
} __attribute__ ((packed)) USBEndpointDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetNumber(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetDirection(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetType(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned short USBEndpointDescriptor_GetMaxPacketSize(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
extern unsigned char USBEndpointDescriptor_GetInterval(
|
||||
const USBEndpointDescriptor *endpoint);
|
||||
|
||||
#endif //#ifndef USBENDPOINTDESCRIPTOR_H
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBFeatureRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBFeatureRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBFeatureRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
|
||||
/// request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Feature selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetValue(request);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the test that the device must undertake following a
|
||||
/// SET_FEATURE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Test selector.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating CLEAR_FEATURE and SET_FEATURE
|
||||
requests.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- To get USB feature request information (field values) from the
|
||||
USBGenericRequest instance, use
|
||||
- USBFeatureRequest_GetFeatureSelector
|
||||
- USBFeatureRequest_GetTestSelector
|
||||
*/
|
||||
|
||||
#ifndef USBFEATUREREQUEST_H
|
||||
#define USBFEATUREREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature Request definitions"
|
||||
///
|
||||
/// This page lists codes of USB Feature Request
|
||||
///
|
||||
/// - USB Feature selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
///
|
||||
/// - USB Test mode selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Feature selectors"
|
||||
///
|
||||
/// This page lists codes of USB feature selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_ENDPOINTHALT
|
||||
/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
|
||||
/// - USBFeatureRequest_TESTMODE
|
||||
|
||||
/// Halt feature of an endpoint.
|
||||
#define USBFeatureRequest_ENDPOINTHALT 0
|
||||
/// Remote wake-up feature of the device.
|
||||
#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
|
||||
/// Test mode of the device.
|
||||
#define USBFeatureRequest_TESTMODE 2
|
||||
/// OTG set feature
|
||||
#define USBFeatureRequest_OTG 0x0B
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/// On The Go Feature Selectors
|
||||
/// b_hnp_enable 3
|
||||
/// a_hnp_support 4
|
||||
/// a_alt_hnp_support 5
|
||||
#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
|
||||
#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
|
||||
#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Test mode selectors"
|
||||
///
|
||||
/// This page lists codes of USB high speed test mode selectors.
|
||||
///
|
||||
/// !Selectors
|
||||
/// - USBFeatureRequest_TESTJ
|
||||
/// - USBFeatureRequest_TESTK
|
||||
/// - USBFeatureRequest_TESTSE0NAK
|
||||
/// - USBFeatureRequest_TESTPACKET
|
||||
/// - USBFeatureRequest_TESTFORCEENABLE
|
||||
/// - USBFeatureRequest_TESTSENDZLP
|
||||
|
||||
/// Tests the high-output drive level on the D+ line.
|
||||
#define USBFeatureRequest_TESTJ 1
|
||||
/// Tests the high-output drive level on the D- line.
|
||||
#define USBFeatureRequest_TESTK 2
|
||||
/// Tests the output impedance, low-level output voltage and loading
|
||||
/// characteristics.
|
||||
#define USBFeatureRequest_TESTSE0NAK 3
|
||||
/// Tests rise and fall times, eye patterns and jitter.
|
||||
#define USBFeatureRequest_TESTPACKET 4
|
||||
/// Tests the hub disconnect detection.
|
||||
#define USBFeatureRequest_TESTFORCEENABLE 5
|
||||
/// Send a ZLP in Test Mode.
|
||||
#define USBFeatureRequest_TESTSENDZLP 6
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetFeatureSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBFeatureRequest_GetTestSelector(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBFEATUREREQUEST_H
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericDescriptor implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericDescriptor class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericDescriptor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the length of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Length of descriptor in bytes.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of a descriptor.
|
||||
/// \param descriptor Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return descriptor->bDescriptorType;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns a pointer to the descriptor right after the given one, when
|
||||
/// parsing a Configuration descriptor.
|
||||
/// \param descriptor - Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Pointer to the next descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor)
|
||||
{
|
||||
return (USBGenericDescriptor *)
|
||||
(((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \unit
|
||||
///
|
||||
/// !!!Purpose
|
||||
///
|
||||
/// Definition of a generic USB descriptor class.
|
||||
///
|
||||
/// !!!Usage
|
||||
///
|
||||
/// -# Declare or access USB descriptors by USBGenericDescriptor instance.
|
||||
/// -# To get usful information (field values) from the USB descriptors, use
|
||||
/// - USBGenericDescriptor_GetLength
|
||||
/// - USBGenericDescriptor_GetType
|
||||
/// -# To scan the descriptors, use
|
||||
/// - USBGenericDescriptor_GetNextDescriptor
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef USBGENERICDESCRIPTOR_H
|
||||
#define USBGENERICDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Descriptor types"
|
||||
///
|
||||
/// This page lists the codes of the usb descriptor types
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericDescriptor_DEVICE
|
||||
/// - USBGenericDescriptor_CONFIGURATION
|
||||
/// - USBGenericDescriptor_STRING
|
||||
/// - USBGenericDescriptor_INTERFACE
|
||||
/// - USBGenericDescriptor_ENDPOINT
|
||||
/// - USBGenericDescriptor_DEVICEQUALIFIER
|
||||
/// - USBGenericDescriptor_OTHERSPEEDCONFIGURATION
|
||||
/// - USBGenericDescriptor_INTERFACEPOWER
|
||||
/// - USBGenericDescriptor_OTG
|
||||
/// - USBGenericDescriptor_DEBUG
|
||||
/// - USBGenericDescriptor_INTERFACEASSOCIATION
|
||||
|
||||
/// Device descriptor type.
|
||||
#define USBGenericDescriptor_DEVICE 1
|
||||
/// Configuration descriptor type.
|
||||
#define USBGenericDescriptor_CONFIGURATION 2
|
||||
/// String descriptor type.
|
||||
#define USBGenericDescriptor_STRING 3
|
||||
/// Interface descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACE 4
|
||||
/// Endpoint descriptor type.
|
||||
#define USBGenericDescriptor_ENDPOINT 5
|
||||
/// Device qualifier descriptor type.
|
||||
#define USBGenericDescriptor_DEVICEQUALIFIER 6
|
||||
/// Other speed configuration descriptor type.
|
||||
#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
|
||||
/// Interface power descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEPOWER 8
|
||||
/// On-The-Go descriptor type.
|
||||
#define USBGenericDescriptor_OTG 9
|
||||
/// Debug descriptor type.
|
||||
#define USBGenericDescriptor_DEBUG 10
|
||||
/// Interface association descriptor type.
|
||||
#define USBGenericDescriptor_INTERFACEASSOCIATION 11
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/// Holds the few fields shared by all USB descriptors.
|
||||
typedef struct {
|
||||
|
||||
/// Length of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type.
|
||||
unsigned char bDescriptorType;
|
||||
|
||||
} __attribute__ ((packed)) USBGenericDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned int USBGenericDescriptor_GetLength(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern unsigned char USBGenericDescriptor_GetType(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
|
||||
const USBGenericDescriptor *descriptor);
|
||||
|
||||
#endif //#ifndef USBGENERICDESCRIPTOR_H
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGenericRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGenericRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return "USB Request Types"
|
||||
//------------------------------------------------------------------------------
|
||||
extern unsigned char USBGenericRequest_GetType(const USBGenericRequest *request)
|
||||
{
|
||||
return ((request->bmRequestType >> 5) & 0x3);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the request code of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request code.
|
||||
/// \sa "USB Request Codes"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRequest(const USBGenericRequest *request)
|
||||
{
|
||||
return request->bRequest;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wValue field of the given request.
|
||||
/// \param request - Pointer to a USBGenericRequest instance.
|
||||
/// \return Request value.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetValue(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wValue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the wIndex field of the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request index;
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetIndex(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wIndex;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the expected length of the data phase following a request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Length of data phase.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned short USBGenericRequest_GetLength(const USBGenericRequest *request)
|
||||
{
|
||||
return request->wLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the endpoint number targetted by a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Endpoint number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return USBGenericRequest_GetIndex(request) & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the intended recipient of a given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Request recipient.
|
||||
/// \sa "USB Request Recipients"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetRecipient(const USBGenericRequest *request)
|
||||
{
|
||||
// Recipient is in bits [0..4] of the bmRequestType field
|
||||
return request->bmRequestType & 0xF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the direction of the data transfer following the given request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Transfer direction.
|
||||
/// \sa "USB Request Directions"
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGenericRequest_GetDirection(const USBGenericRequest *request)
|
||||
{
|
||||
// Transfer direction is located in bit D7 of the bmRequestType field
|
||||
if ((request->bmRequestType & 0x80) != 0) {
|
||||
|
||||
return USBGenericRequest_IN;
|
||||
}
|
||||
else {
|
||||
|
||||
return USBGenericRequest_OUT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGenericRequest class and its methods.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# Declare or access USB requests by USBGenericRequest instance.
|
||||
-# To get usful information (field values) from the USB requests, use
|
||||
- USBGenericRequest_GetType
|
||||
- USBGenericRequest_GetRequest
|
||||
- USBGenericRequest_GetValue
|
||||
- USBGenericRequest_GetIndex
|
||||
- USBGenericRequest_GetLength
|
||||
- USBGenericRequest_GetEndpointNumber
|
||||
- USBGenericRequest_GetRecipient
|
||||
- USBGenericRequest_GetDirection
|
||||
*/
|
||||
|
||||
#ifndef USBGENERICREQUEST_H
|
||||
#define USBGENERICREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Generic Request definitions"
|
||||
///
|
||||
/// This page lists the codes of USB generic request.
|
||||
///
|
||||
/// - USB Request codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
///
|
||||
/// - USB Request Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
///
|
||||
/// - USB Request Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
///
|
||||
/// - USB Request Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request codes"
|
||||
///
|
||||
/// This page lists the USB generic request codes.
|
||||
///
|
||||
/// !Codes
|
||||
/// - USBGenericRequest_GETSTATUS
|
||||
/// - USBGenericRequest_CLEARFEATURE
|
||||
/// - USBGenericRequest_SETFEATURE
|
||||
/// - USBGenericRequest_SETADDRESS
|
||||
/// - USBGenericRequest_GETDESCRIPTOR
|
||||
/// - USBGenericRequest_SETDESCRIPTOR
|
||||
/// - USBGenericRequest_GETCONFIGURATION
|
||||
/// - USBGenericRequest_SETCONFIGURATION
|
||||
/// - USBGenericRequest_GETINTERFACE
|
||||
/// - USBGenericRequest_SETINTERFACE
|
||||
/// - USBGenericRequest_SYNCHFRAME
|
||||
|
||||
/// GET_STATUS request code.
|
||||
#define USBGenericRequest_GETSTATUS 0
|
||||
/// CLEAR_FEATURE request code.
|
||||
#define USBGenericRequest_CLEARFEATURE 1
|
||||
/// SET_FEATURE request code.
|
||||
#define USBGenericRequest_SETFEATURE 3
|
||||
/// SET_ADDRESS request code.
|
||||
#define USBGenericRequest_SETADDRESS 5
|
||||
/// GET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_GETDESCRIPTOR 6
|
||||
/// SET_DESCRIPTOR request code.
|
||||
#define USBGenericRequest_SETDESCRIPTOR 7
|
||||
/// GET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_GETCONFIGURATION 8
|
||||
/// SET_CONFIGURATION request code.
|
||||
#define USBGenericRequest_SETCONFIGURATION 9
|
||||
/// GET_INTERFACE request code.
|
||||
#define USBGenericRequest_GETINTERFACE 10
|
||||
/// SET_INTERFACE request code.
|
||||
#define USBGenericRequest_SETINTERFACE 11
|
||||
/// SYNCH_FRAME request code.
|
||||
#define USBGenericRequest_SYNCHFRAME 12
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Recipients"
|
||||
///
|
||||
/// This page lists codes of USB request recipients.
|
||||
///
|
||||
/// !Recipients
|
||||
/// - USBGenericRequest_DEVICE
|
||||
/// - USBGenericRequest_INTERFACE
|
||||
/// - USBGenericRequest_ENDPOINT
|
||||
/// - USBGenericRequest_OTHER
|
||||
|
||||
/// Recipient is the whole device.
|
||||
#define USBGenericRequest_DEVICE 0
|
||||
/// Recipient is an interface.
|
||||
#define USBGenericRequest_INTERFACE 1
|
||||
/// Recipient is an endpoint.
|
||||
#define USBGenericRequest_ENDPOINT 2
|
||||
/// Recipient is another entity.
|
||||
#define USBGenericRequest_OTHER 3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Types"
|
||||
///
|
||||
/// This page lists codes of USB request types.
|
||||
///
|
||||
/// !Types
|
||||
/// - USBGenericRequest_STANDARD
|
||||
/// - USBGenericRequest_CLASS
|
||||
/// - USBGenericRequest_VENDOR
|
||||
|
||||
/// Request is standard.
|
||||
#define USBGenericRequest_STANDARD 0
|
||||
/// Request is class-specific.
|
||||
#define USBGenericRequest_CLASS 1
|
||||
/// Request is vendor-specific.
|
||||
#define USBGenericRequest_VENDOR 2
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \page "USB Request Directions"
|
||||
///
|
||||
/// This page lists codes of USB request directions.
|
||||
///
|
||||
/// !Directions
|
||||
/// - USBGenericRequest_IN
|
||||
/// - USBGenericRequest_OUT
|
||||
|
||||
/// Transfer occurs from device to the host.
|
||||
#define USBGenericRequest_OUT 0
|
||||
/// Transfer occurs from the host to the device.
|
||||
#define USBGenericRequest_IN 1
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Generic USB SETUP request sent over Control endpoints.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Type of request
|
||||
/// \sa "USB Request Recipients"
|
||||
/// \sa "USB Request Types"
|
||||
/// \sa "USB Request Directions"
|
||||
unsigned char bmRequestType:8;
|
||||
/// Request code
|
||||
/// \sa "USB Request Codes"
|
||||
unsigned char bRequest:8;
|
||||
/// Request-specific value parameter.
|
||||
unsigned short wValue:16;
|
||||
/// Request-specific index parameter.
|
||||
unsigned short wIndex:16;
|
||||
/// Expected length (in bytes) of the data phase.
|
||||
unsigned short wLength:16;
|
||||
|
||||
} USBGenericRequest;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGenericRequest_GetType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRequest(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetValue(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned short USBGenericRequest_GetLength(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetEndpointNumber(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetRecipient(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGenericRequest_GetDirection(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGENERICREQUEST_H
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBGetDescriptorRequest implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USBGetDescriptorRequest class.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGetDescriptorRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the type of the descriptor requested by the host given the
|
||||
/// corresponding GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Type of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor type is in the high-byte of the wValue field
|
||||
return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Returns the index of the requested descriptor, given the corresponding
|
||||
/// GET_DESCRIPTOR request.
|
||||
/// \param request Pointer to a USBGenericDescriptor instance.
|
||||
/// \return Index of the requested descriptor.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
// Requested descriptor index if in the low byte of the wValue field
|
||||
return USBGenericRequest_GetValue(request) & 0xFF;
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of the USBGetDescriptorRequest class.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- After a GET_DESCRIPTOR request has been received, retrive the useful
|
||||
values with following functions:
|
||||
- USBGetDescriptorRequest_GetDescriptorType: the descriptor type
|
||||
- USBGetDescriptorRequest_GetDescriptorIndex: the index of the requested
|
||||
descriptor
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
#define USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorType(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
extern unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBGETDESCRIPTORREQUEST_H
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* \page USBInterfaceAssociateDescriptor
|
||||
* !!!Purpose
|
||||
*
|
||||
* Class for manipulating USB IAD descriptors.
|
||||
*
|
||||
* !!!Usage
|
||||
*
|
||||
* -# Test
|
||||
*/
|
||||
|
||||
#ifndef USBDIADDESCRIPTOR_H
|
||||
#define USBDIADDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
/*
|
||||
Type: USBDeviceDescriptor
|
||||
USB standard device descriptor structure.
|
||||
|
||||
Variables:
|
||||
bLength - Size of this descriptor in bytes.
|
||||
bDescriptorType - Descriptor type (<USBGenericDescriptor_IAD>).
|
||||
bFirstInterface - Interface number of the first interface that is
|
||||
associated with this function.
|
||||
bInterfaceCount - Number of contiguous interfaces that are
|
||||
associated with this function.
|
||||
bFunctionClass - Class code (assigned by USB-IF).
|
||||
bFunctionSubClass - Subclass code (assigned by USB-IF).
|
||||
bFunctionProtocol - Protocol code (assigned by USB-IF)
|
||||
iFunction - Index of string descriptor describing this function.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
unsigned char bLength;
|
||||
unsigned char bDescriptorType;
|
||||
unsigned char bFirstInterface;
|
||||
unsigned char bInterfaceCount;
|
||||
unsigned char bFunctionClass;
|
||||
unsigned char bFunctionSubClass;
|
||||
unsigned char bFunctionProtocol;
|
||||
unsigned char iFunction;
|
||||
} __attribute__ ((packed)) USBInterfaceAssociationDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBDIADDESCRIPTOR_H
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definition of a class for manipulating USB interface descriptors.
|
||||
|
||||
!!!Usage
|
||||
|
||||
- Declare USBInterfaceDescriptor instance as a part of the configuration
|
||||
descriptors of a USB device.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
#define USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack(1) // IAR
|
||||
#define __attribute__(...) // IAR
|
||||
#endif // IAR
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// USB standard interface descriptor structure.
|
||||
//------------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
|
||||
/// Size of the descriptor in bytes.
|
||||
unsigned char bLength;
|
||||
/// Descriptor type (USBGenericDescriptor_INTERFACE).
|
||||
unsigned char bDescriptorType;
|
||||
/// Number of the interface in its configuration.
|
||||
unsigned char bInterfaceNumber;
|
||||
/// Value to select this alternate interface setting.
|
||||
unsigned char bAlternateSetting;
|
||||
/// Number of endpoints used by the inteface (excluding endpoint 0).
|
||||
unsigned char bNumEndpoints;
|
||||
/// Interface class code.
|
||||
unsigned char bInterfaceClass;
|
||||
/// Interface subclass code.
|
||||
unsigned char bInterfaceSubClass;
|
||||
/// Interface protocol code.
|
||||
unsigned char bInterfaceProtocol;
|
||||
/// Index of the interface string descriptor.
|
||||
unsigned char iInterface;
|
||||
|
||||
} __attribute__ ((packed)) USBInterfaceDescriptor; // GCC
|
||||
|
||||
#ifdef __ICCARM__ // IAR
|
||||
#pragma pack() // IAR
|
||||
#endif // IAR
|
||||
|
||||
#endif //#ifndef USBINTERFACEDESCRIPTOR_H
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBInterfaceRequest
|
||||
|
||||
About: Purpose
|
||||
Implementation of USBInterfaceRequest class methods.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBInterfaceRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates which interface is targetted by a GET_INTERFACE or
|
||||
/// SET_INTERFACE request.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return Interface number.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetIndex(request) & 0xFF);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Indicates the new alternate setting that the interface targetted by a
|
||||
/// SET_INTERFACE request should use.
|
||||
/// \param request Pointer to a USBGenericRequest instance.
|
||||
/// \return New active setting for the interface.
|
||||
//------------------------------------------------------------------------------
|
||||
unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
return (USBGenericRequest_GetValue(request) & 0xFF);
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Definitions for manipulating SET_INTERFACE and GET_INTERFACE request.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# After a SET_INTERFACE request has been received, retrieve the
|
||||
target interface using USBInterfaceRequest_GetInterface and its
|
||||
new alternate setting with USBInterfaceRequest_GetAlternateSetting.
|
||||
-# After a GET_INTERFACE request has been received, retrieve the target
|
||||
interface using USBInterfaceRequest_GetInterface.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBINTERFACEREQUEST_H
|
||||
#define USBINTERFACEREQUEST_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "../../../usb/common/core/USBGenericRequest.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetInterface(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
|
||||
extern unsigned char USBInterfaceRequest_GetAlternateSetting(
|
||||
const USBGenericRequest *request);
|
||||
|
||||
#endif //#ifndef USBINTERFACEREQUEST_H
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
Title: USBIrqHandler implementation
|
||||
|
||||
About: Purpose
|
||||
Implementation of the USB Interrupt Handler.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Headers
|
||||
//------------------------------------------------------------------------------
|
||||
#include <exceptions.h>
|
||||
|
||||
#include "radio/src/targets/sky9x/board_lowlevel.h"
|
||||
#include "../../../usb/device/core/USBD.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
/// Call Arbitrer, device and host interrupt handler.
|
||||
/// The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
//------------------------------------------------------------------------------
|
||||
void USB_IrqHandler( void )
|
||||
{
|
||||
// Most arbitrer interrupt
|
||||
usb_general_interrupt();
|
||||
// Device interrupt
|
||||
USBD_IrqHandler();
|
||||
// Host interrupt
|
||||
usb_pipe_interrupt();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
\unit
|
||||
|
||||
!!!Purpose
|
||||
|
||||
Implementation of the USB Interrupt Handler.
|
||||
|
||||
!!!Usage
|
||||
|
||||
-# The IRQ functions are defined with weak and can be surcharged if needed.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef USBIRQHANDLER_H
|
||||
#define USBIRQHANDLER_H
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exported functions
|
||||
//------------------------------------------------------------------------------
|
||||
extern void USB_IrqHandler( void );
|
||||
|
||||
#endif //#ifndef USBIRQHANDLER_H
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user