parent
40150c5fc6
commit
0aa76da9f2
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* @file backup_ram.cpp
|
||||
*
|
||||
* @date May 22, 2020
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "backup_ram.h"
|
||||
#include "flash.h"
|
||||
|
||||
#define BACKUP_NOT_INITIALIZED 0xFFFF
|
||||
#define BACKUP_SAVED 0x5555
|
||||
#define BACKUP_PENDING 0x0000
|
||||
|
||||
// we store the flash state at 0 index + all backup variables
|
||||
static volatile uint32_t backupRam[BACKUP_RAM_NUM + 1];
|
||||
static bool wasLoaded = false;
|
||||
// these offsets are indices in the 'BACKUP_FLASH_ADDR' (32-bit array)
|
||||
static const int backupStateOffset = 0, backupDataOffset = 1;
|
||||
const size_t backupSize = (BACKUP_RAM_NUM + 1) * sizeof(uint32_t);
|
||||
|
||||
static void backupInit(void) {
|
||||
static_assert(backupSize <= BACKUP_FLASH_SIZE, "Backup flash overflow");
|
||||
|
||||
// first, load the whole buffer into the memory
|
||||
flashRead((flashaddr_t)BACKUP_FLASH_ADDR, (char *)backupRam, backupSize);
|
||||
// check if we have a reliable properly saved data
|
||||
if (backupRam[backupStateOffset] != BACKUP_SAVED) {
|
||||
// zero is the default value
|
||||
memset((void *)backupRam, 0, backupSize);
|
||||
}
|
||||
|
||||
// we cannot trust the saved data anymore, until it's saved in backupRamFlush()
|
||||
// so we mark is as 'pending'
|
||||
backupRam[backupStateOffset] = BACKUP_PENDING;
|
||||
flashWrite(BACKUP_FLASH_ADDR + backupStateOffset, (char *)backupRam, sizeof(backupRam[backupStateOffset]));
|
||||
|
||||
wasLoaded = true;
|
||||
}
|
||||
|
||||
uint32_t backupRamLoad(backup_ram_e idx) {
|
||||
// this is executed only once during the firmware init
|
||||
if (!wasLoaded) {
|
||||
backupInit();
|
||||
}
|
||||
|
||||
return backupRam[idx + backupDataOffset];
|
||||
}
|
||||
|
||||
void backupRamSave(backup_ram_e idx, uint32_t value) {
|
||||
// this is executed only once during the firmware init
|
||||
if (!wasLoaded) {
|
||||
backupInit();
|
||||
}
|
||||
|
||||
backupRam[idx + backupDataOffset] = value;
|
||||
}
|
||||
|
||||
void backupRamFlush(void) {
|
||||
|
||||
// todo: implement an incremental "append-to-the-end" algorithm to minimize sector erasings?
|
||||
|
||||
// Enter the critical zone
|
||||
syssts_t sts = chSysGetStatusAndLockX();
|
||||
|
||||
// rewrite the whole sector
|
||||
flashErase((flashaddr_t)BACKUP_FLASH_ADDR, BACKUP_FLASH_SIZE);
|
||||
// mark the data as valid & saved
|
||||
backupRam[backupStateOffset] = BACKUP_SAVED;
|
||||
// save the data to the flash
|
||||
flashWrite((flashaddr_t)BACKUP_FLASH_ADDR, (char *)backupRam, backupSize);
|
||||
|
||||
// Leaving the critical zone
|
||||
chSysRestoreStatusX(sts);
|
||||
|
||||
// there should not be any backup-RAM activity after this call
|
||||
// but if there is, at least try to reinitialize...
|
||||
wasLoaded = false;
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/**
|
||||
* @file cypress_common.cpp
|
||||
* @brief Low level common Cypress code
|
||||
*
|
||||
* @date Jan 28, 2020
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "engine.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||
|
||||
// ADC_CHANNEL_IN0 // PA2 (def=VIGN)
|
||||
// ADC_CHANNEL_IN1 // PA3 (def=MAP4)
|
||||
// ADC_CHANNEL_IN2 // x
|
||||
// ADC_CHANNEL_IN3 // PD3 (def=MAP3)
|
||||
// ADC_CHANNEL_IN4 // x
|
||||
// ADC_CHANNEL_IN5 // x
|
||||
// ADC_CHANNEL_IN6 // x
|
||||
// ADC_CHANNEL_IN7 // PB12 (def=MAP2)
|
||||
// ADC_CHANNEL_IN8 // PB13 (def=MAP1)
|
||||
// ADC_CHANNEL_IN9 // x
|
||||
// ADC_CHANNEL_IN10 // PE2 (def=O2S2)
|
||||
// ADC_CHANNEL_IN11 // x
|
||||
// ADC_CHANNEL_IN12 // PC14 (def=O2S)
|
||||
// ADC_CHANNEL_IN13 // PC15 (def=TPS)
|
||||
// ADC_CHANNEL_IN14 // PC16 (def=CLT)
|
||||
// ADC_CHANNEL_IN15 // PC17 (def=IAT)
|
||||
|
||||
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel) {
|
||||
// todo: replace this with an array :)
|
||||
switch (hwChannel) {
|
||||
case EFI_ADC_0:
|
||||
return GPIOB_0;
|
||||
case EFI_ADC_1:
|
||||
return GPIOB_1;
|
||||
case EFI_ADC_2:
|
||||
return GPIOB_2;
|
||||
case EFI_ADC_3:
|
||||
return GPIOB_3;
|
||||
case EFI_ADC_4:
|
||||
return GPIOB_4;
|
||||
case EFI_ADC_5:
|
||||
return GPIOB_5;
|
||||
case EFI_ADC_6:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_7:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_8:
|
||||
return GPIOB_8;
|
||||
case EFI_ADC_9:
|
||||
return GPIOB_9;
|
||||
case EFI_ADC_10:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_11:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_12:
|
||||
return GPIOB_12;
|
||||
case EFI_ADC_13:
|
||||
return GPIOB_13;
|
||||
case EFI_ADC_14:
|
||||
return GPIOB_14;
|
||||
case EFI_ADC_15:
|
||||
return GPIOB_15;
|
||||
case EFI_ADC_16:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_17:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_18:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_19:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_20:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_21:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_22:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_23:
|
||||
return GPIO_INVALID;
|
||||
case EFI_ADC_24:
|
||||
return GPIOC_10;
|
||||
case EFI_ADC_25:
|
||||
return GPIOC_9;
|
||||
case EFI_ADC_26:
|
||||
return GPIOC_8;
|
||||
case EFI_ADC_27:
|
||||
return GPIOC_7;
|
||||
case EFI_ADC_28:
|
||||
return GPIOC_5;
|
||||
case EFI_ADC_29:
|
||||
return GPIOC_4;
|
||||
case EFI_ADC_30:
|
||||
return GPIOC_3;
|
||||
case EFI_ADC_31:
|
||||
return GPIOC_2;
|
||||
default:
|
||||
firmwareError(CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg);
|
||||
return GPIO_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
adc_channel_e getAdcChannel(brain_pin_e pin) {
|
||||
switch (pin) {
|
||||
case GPIOB_0:
|
||||
return EFI_ADC_0;
|
||||
case GPIOB_1:
|
||||
return EFI_ADC_1;
|
||||
case GPIOB_2:
|
||||
return EFI_ADC_2;
|
||||
case GPIOB_3:
|
||||
return EFI_ADC_3;
|
||||
case GPIOB_4:
|
||||
return EFI_ADC_4;
|
||||
case GPIOB_5:
|
||||
return EFI_ADC_5;
|
||||
case GPIOB_8:
|
||||
return EFI_ADC_8;
|
||||
case GPIOB_9:
|
||||
return EFI_ADC_9;
|
||||
case GPIOB_12:
|
||||
return EFI_ADC_12;
|
||||
case GPIOB_13:
|
||||
return EFI_ADC_13;
|
||||
case GPIOB_14:
|
||||
return EFI_ADC_14;
|
||||
case GPIOB_15:
|
||||
return EFI_ADC_15;
|
||||
case GPIOC_10:
|
||||
return EFI_ADC_24;
|
||||
case GPIOC_9:
|
||||
return EFI_ADC_25;
|
||||
case GPIOC_8:
|
||||
return EFI_ADC_26;
|
||||
case GPIOC_7:
|
||||
return EFI_ADC_27;
|
||||
case GPIOC_5:
|
||||
return EFI_ADC_28;
|
||||
case GPIOC_4:
|
||||
return EFI_ADC_29;
|
||||
case GPIOC_3:
|
||||
return EFI_ADC_30;
|
||||
case GPIOC_2:
|
||||
return EFI_ADC_31;
|
||||
default:
|
||||
return EFI_ADC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// deprecated - migrate to 'getAdcChannelBrainPin'
|
||||
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel) {
|
||||
return getHwPort(msg, getAdcChannelBrainPin(msg, hwChannel));
|
||||
}
|
||||
|
||||
// deprecated - migrate to 'getAdcChannelBrainPin'
|
||||
int getAdcChannelPin(adc_channel_e hwChannel) {
|
||||
return getHwPin("get_pin", getAdcChannelBrainPin("get_pin", hwChannel));
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_ADC */
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
void jump_to_bootloader() {
|
||||
// todo:
|
||||
// Will not return from here
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
|
@ -0,0 +1,180 @@
|
|||
/**
|
||||
* @file cypress_pins.cpp
|
||||
* @brief Cypress-compatible GPIO code
|
||||
*
|
||||
* @date Jun 02, 2019
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "engine.h"
|
||||
#include "efi_gpio.h"
|
||||
|
||||
#if EFI_GPIO_HARDWARE
|
||||
|
||||
#define PORT_SIZE 16
|
||||
|
||||
static ioportid_t ports[] = {
|
||||
GPIOA,
|
||||
GPIOB,
|
||||
GPIOC,
|
||||
GPIOD,
|
||||
GPIOE,
|
||||
GPIOF,
|
||||
GPIOG,
|
||||
GPIOH,
|
||||
GPIOI,
|
||||
GPIOJ,
|
||||
GPIOK,
|
||||
};
|
||||
|
||||
static brain_pin_e portMap[16] = {
|
||||
GPIOA_0, GPIOB_0, GPIOC_0, GPIOD_0, GPIOE_0, GPIOF_0, GPIO_INVALID, GPIOG_0, GPIO_INVALID, GPIO_INVALID, GPIOH_0, GPIOI_0, GPIOJ_0, GPIO_INVALID, GPIO_INVALID, GPIOK_0
|
||||
};
|
||||
|
||||
#define PIN_REPO_SIZE (sizeof(ports) / sizeof(ports[0])) * PORT_SIZE
|
||||
// todo: move this into PinRepository class
|
||||
static const char *PIN_USED[PIN_REPO_SIZE + BOARD_EXT_PINREPOPINS];
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "io_pins.h"
|
||||
|
||||
/**
|
||||
* @deprecated - use hwPortname() instead
|
||||
*/
|
||||
const char *portname(ioportid_t GPIOx) {
|
||||
if (GPIOx == GPIOA)
|
||||
return "P0";
|
||||
if (GPIOx == GPIOB)
|
||||
return "P1";
|
||||
if (GPIOx == GPIOC)
|
||||
return "P2";
|
||||
if (GPIOx == GPIOD)
|
||||
return "P3";
|
||||
if (GPIOx == GPIOE)
|
||||
return "P4";
|
||||
if (GPIOx == GPIOF)
|
||||
return "P5";
|
||||
if (GPIOx == GPIOG)
|
||||
return "P7";
|
||||
if (GPIOx == GPIOH)
|
||||
return "PA";
|
||||
if (GPIOx == GPIOI)
|
||||
return "PB";
|
||||
if (GPIOx == GPIOJ)
|
||||
return "PC";
|
||||
if (GPIOx == GPIOK)
|
||||
return "PF";
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static int getPortIndex(ioportid_t port) {
|
||||
efiAssert(CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
|
||||
if (port == GPIOA)
|
||||
return 0;
|
||||
if (port == GPIOB)
|
||||
return 1;
|
||||
if (port == GPIOC)
|
||||
return 2;
|
||||
if (port == GPIOD)
|
||||
return 3;
|
||||
if (port == GPIOE)
|
||||
return 4;
|
||||
if (port == GPIOF)
|
||||
return 5;
|
||||
if (port == GPIOG)
|
||||
return 6;
|
||||
if (port == GPIOH)
|
||||
return 7;
|
||||
if (port == GPIOI)
|
||||
return 8;
|
||||
if (port == GPIOJ)
|
||||
return 9;
|
||||
if (port == GPIOK)
|
||||
return 10;
|
||||
firmwareError(CUSTOM_ERR_UNKNOWN_PORT, "unknown port");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ioportid_t getBrainPort(brain_pin_e brainPin) {
|
||||
return ports[(brainPin - GPIOA_0) / PORT_SIZE];
|
||||
}
|
||||
|
||||
int getBrainPinIndex(brain_pin_e brainPin) {
|
||||
return (brainPin - GPIOA_0) % PORT_SIZE;
|
||||
}
|
||||
|
||||
int getBrainIndex(ioportid_t port, ioportmask_t pin) {
|
||||
int portIndex = getPortIndex(port);
|
||||
return portIndex * PORT_SIZE + pin;
|
||||
}
|
||||
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
return GPIO_NULL;
|
||||
if (brainPin < GPIOA_0 || brainPin > BRAIN_PIN_LAST_ONCHIP) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return GPIO_NULL;
|
||||
}
|
||||
return ports[(brainPin - GPIOA_0) / PORT_SIZE];
|
||||
}
|
||||
|
||||
/**
|
||||
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
|
||||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
|
||||
{
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
if (brain_pin_is_onchip(brainPin))
|
||||
return getBrainPinIndex(brainPin);
|
||||
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip brain_pin_e: %d", msg, brainPin);
|
||||
return EFI_ERROR_CODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse string representation of physical pin into brain_pin_e ordinal.
|
||||
*
|
||||
* @return GPIO_UNASSIGNED for "none", GPIO_INVALID for invalid entry
|
||||
*/
|
||||
brain_pin_e parseBrainPin(const char *str) {
|
||||
if (strEqual(str, "none"))
|
||||
return GPIO_UNASSIGNED;
|
||||
// todo: create method toLowerCase?
|
||||
if (str[0] != 'p' && str[0] != 'P') {
|
||||
return GPIO_INVALID;
|
||||
}
|
||||
char port = str[1];
|
||||
if (port >= 'a' && port <= 'z') {
|
||||
port = 10 + (port - 'a');
|
||||
} else if (port >= 'A' && port <= 'Z') {
|
||||
port = 10 + (port - 'A');
|
||||
} else if (port >= '0' && port <= '9') {
|
||||
port = 0 + (port - '0');
|
||||
} else {
|
||||
return GPIO_INVALID;
|
||||
}
|
||||
brain_pin_e basePin = portMap[(int)port];
|
||||
if (basePin == GPIO_INVALID)
|
||||
return GPIO_INVALID;
|
||||
const char *pinStr = str + 2;
|
||||
int pin = atoi(pinStr);
|
||||
return (brain_pin_e)(basePin + pin);
|
||||
}
|
||||
|
||||
unsigned int getNumBrainPins(void) {
|
||||
return PIN_REPO_SIZE;
|
||||
}
|
||||
|
||||
void initBrainUsedPins(void) {
|
||||
memset(PIN_USED, 0, sizeof(PIN_USED));
|
||||
}
|
||||
|
||||
const char* & getBrainUsedPin(unsigned int idx) {
|
||||
return PIN_USED[idx];
|
||||
}
|
||||
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
*
|
||||
* @file flash.c
|
||||
* @brief Lower-level code for Cypress related to internal flash memory
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#if EFI_INTERNAL_FLASH
|
||||
|
||||
#include "flash.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// todo: add DualFlash support
|
||||
|
||||
//#define CYPRESS_FLASH_DEBUG
|
||||
|
||||
typedef uint32_t flashdata_t;
|
||||
|
||||
static volatile uint32_t mainFlashMap[] = {
|
||||
0x00000000, 0x00002000, 0x00004000, 0x00006000, 0x00008000,
|
||||
0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000,
|
||||
0x00060000, 0x00070000, 0x00080000, 0x00090000, 0x000A0000,
|
||||
0x000B0000, 0x000C0000, 0x000D0000, 0x000E0000, 0x000F0000,
|
||||
0x00100000, 0x00102000, 0x00104000, 0x00106000, 0x00108000,
|
||||
0x00110000, 0x00120000, 0x00130000, 0x00140000, 0x00150000,
|
||||
0x00160000, 0x00170000, 0x00180000,
|
||||
// todo: add upper 40k flash area
|
||||
};
|
||||
|
||||
bool flashUnlock(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flashLock(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#define CYPRESS_FLASH_WORD_ALIGNMENT 2
|
||||
|
||||
static int alignToWord(int v) {
|
||||
return (v + CYPRESS_FLASH_WORD_ALIGNMENT - 1) & ~(CYPRESS_FLASH_WORD_ALIGNMENT - 1);
|
||||
}
|
||||
|
||||
static __attribute__((optimize("O0"))) int flashSectorEraseAtAddress(volatile uint32_t sectorStart) {
|
||||
return MFlash_SectorErase((uint16_t*)sectorStart) != Ok ? FLASH_RETURN_BAD_FLASH : FLASH_RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
int __attribute__((optimize("O0"))) flashErase(flashaddr_t address, size_t size) {
|
||||
// todo: this is a temporary hack
|
||||
// todo: why the code below doesn't work with -O2?!
|
||||
if (flashSectorEraseAtAddress(address) != FLASH_RETURN_SUCCESS) {
|
||||
return FLASH_RETURN_BAD_FLASH;
|
||||
}
|
||||
#if 0
|
||||
volatile int i;
|
||||
size = alignToWord(size);
|
||||
|
||||
volatile int numSectors = (sizeof(mainFlashMap) / sizeof(mainFlashMap[0])) - 1;
|
||||
// list through all sectors and erase those inside the given memory area
|
||||
for (i = 0; i < numSectors; i++) {
|
||||
volatile uint32_t sectorStart = mainFlashMap[i];
|
||||
volatile uint32_t sectorEnd = mainFlashMap[i + 1] - 1;
|
||||
// if the sector overlaps the address range
|
||||
if (sectorStart < (address + size) && sectorEnd >= address) {
|
||||
if (flashSectorEraseAtAddress(sectorStart) != FLASH_RETURN_SUCCESS) {
|
||||
return FLASH_RETURN_BAD_FLASH;
|
||||
}
|
||||
// check if erased
|
||||
size_t sectorSize = sectorEnd - sectorStart + 1;
|
||||
if (flashIsErased(sectorStart, sectorSize) == FALSE)
|
||||
return FLASH_RETURN_BAD_FLASH; /* Sector is not empty despite the erase cycle! */
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Successfully deleted sector */
|
||||
return FLASH_RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
int flashWrite(flashaddr_t address, const char* buffer, size_t size) {
|
||||
uint32_t sizeInWords = alignToWord(size) >> 1;
|
||||
return MFlash_WriteData16Bit((uint16_t*)address, (uint16_t*)buffer, sizeInWords) == Ok ? FLASH_RETURN_SUCCESS : FLASH_RETURN_BAD_FLASH;
|
||||
//return MFlash_WriteData16Bit_Fm0Type3CrSecureArea((uint16_t*)address, (uint16_t*)buffer, sizeInWords) == Ok ? 0 : -1;
|
||||
}
|
||||
|
||||
bool flashIsErased(flashaddr_t address, size_t size) {
|
||||
/* Check for default set bits in the flash memory
|
||||
* For efficiency, compare flashdata_t values as much as possible,
|
||||
* then, fallback to byte per byte comparison. */
|
||||
while (size >= sizeof(flashdata_t)) {
|
||||
if (*(volatile flashdata_t*) address != (flashdata_t) (-1)) // flashdata_t being unsigned, -1 is 0xFF..FF
|
||||
return false;
|
||||
address += sizeof(flashdata_t);
|
||||
size -= sizeof(flashdata_t);
|
||||
}
|
||||
while (size > 0) {
|
||||
if (*(char*) address != 0xFF)
|
||||
return false;
|
||||
++address;
|
||||
--size;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool flashCompare(flashaddr_t address, const char* buffer, size_t size) {
|
||||
/* For efficiency, compare flashdata_t values as much as possible,
|
||||
* then, fallback to byte per byte comparison. */
|
||||
while (size >= sizeof(flashdata_t)) {
|
||||
if (*(volatile flashdata_t*) address != *(flashdata_t*) buffer)
|
||||
return FALSE;
|
||||
address += sizeof(flashdata_t);
|
||||
buffer += sizeof(flashdata_t);
|
||||
size -= sizeof(flashdata_t);
|
||||
}
|
||||
while (size > 0) {
|
||||
if (*(volatile char*) address != *buffer)
|
||||
return FALSE;
|
||||
++address;
|
||||
++buffer;
|
||||
--size;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int flashRead(flashaddr_t address, char* buffer, size_t size) {
|
||||
memcpy(buffer, (char*) address, size);
|
||||
return FLASH_RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* EFI_INTERNAL_FLASH */
|
|
@ -0,0 +1,16 @@
|
|||
ifeq ($(CYPRESS_CONTRIB),)
|
||||
CYPRESS_CONTRIB = $(CHIBIOS_CONTRIB)
|
||||
endif
|
||||
|
||||
HW_LAYER_EGT = $(PROJECT_DIR)/hw_layer/ports/cypress/serial_over_usb/usbconfig.c \
|
||||
$(PROJECT_DIR)/hw_layer/ports/cypress/serial_over_usb/usbconsole.c
|
||||
|
||||
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/cypress/flash.c
|
||||
|
||||
HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/cypress/mpu_util.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/ports/cypress/cypress_pins.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/ports/cypress/cypress_common.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/ports/cypress/backup_ram.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/trigger_input_adc.cpp
|
||||
|
||||
HW_INC += $(PROJECT_DIR)/hw_layer/ports/cypress/serial_over_usb
|
|
@ -0,0 +1,253 @@
|
|||
/**
|
||||
* @file mpu_util.cpp
|
||||
*
|
||||
* @date Jul 27, 2014
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "mpu_util.h"
|
||||
#include "flash.h"
|
||||
#include "engine.h"
|
||||
#include "pin_repository.h"
|
||||
#include "os_util.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
extern "C" {
|
||||
void _unhandled_exception(void);
|
||||
void DebugMonitorVector(void);
|
||||
void UsageFaultVector(void);
|
||||
void BusFaultVector(void);
|
||||
void HardFaultVector(void);
|
||||
}
|
||||
|
||||
void baseMCUInit(void) {
|
||||
}
|
||||
|
||||
void _unhandled_exception(void) {
|
||||
/*lint -restore*/
|
||||
|
||||
chDbgPanic3("_unhandled_exception", __FILE__, __LINE__);
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
|
||||
void DebugMonitorVector(void) {
|
||||
chDbgPanic3("DebugMonitorVector", __FILE__, __LINE__);
|
||||
while (TRUE)
|
||||
;
|
||||
}
|
||||
|
||||
void UsageFaultVector(void) {
|
||||
chDbgPanic3("UsageFaultVector", __FILE__, __LINE__);
|
||||
while (TRUE)
|
||||
;
|
||||
}
|
||||
|
||||
void BusFaultVector(void) {
|
||||
chDbgPanic3("BusFaultVector", __FILE__, __LINE__);
|
||||
while (TRUE) {
|
||||
}
|
||||
}
|
||||
|
||||
void HardFaultVector(void) {
|
||||
while (TRUE) {
|
||||
}
|
||||
}
|
||||
|
||||
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
||||
bool isSpiInitialized[5] = { false, false, false, false, false };
|
||||
|
||||
static int getSpiAf(SPIDriver *driver) {
|
||||
#if STM32_SPI_USE_SPI1
|
||||
if (driver == &SPID1) {
|
||||
return EFI_SPI1_AF;
|
||||
}
|
||||
#endif
|
||||
#if STM32_SPI_USE_SPI2
|
||||
if (driver == &SPID2) {
|
||||
return EFI_SPI2_AF;
|
||||
}
|
||||
#endif
|
||||
#if STM32_SPI_USE_SPI3
|
||||
if (driver == &SPID3) {
|
||||
return EFI_SPI3_AF;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
brain_pin_e getMisoPin(spi_device_e device) {
|
||||
switch(device) {
|
||||
case SPI_DEVICE_1:
|
||||
return CONFIG(spi1misoPin);
|
||||
case SPI_DEVICE_2:
|
||||
return CONFIG(spi2misoPin);
|
||||
case SPI_DEVICE_3:
|
||||
return CONFIG(spi3misoPin);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return GPIO_UNASSIGNED;
|
||||
}
|
||||
|
||||
brain_pin_e getMosiPin(spi_device_e device) {
|
||||
switch(device) {
|
||||
case SPI_DEVICE_1:
|
||||
return CONFIG(spi1mosiPin);
|
||||
case SPI_DEVICE_2:
|
||||
return CONFIG(spi2mosiPin);
|
||||
case SPI_DEVICE_3:
|
||||
return CONFIG(spi3mosiPin);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return GPIO_UNASSIGNED;
|
||||
}
|
||||
|
||||
brain_pin_e getSckPin(spi_device_e device) {
|
||||
switch(device) {
|
||||
case SPI_DEVICE_1:
|
||||
return CONFIG(spi1sckPin);
|
||||
case SPI_DEVICE_2:
|
||||
return CONFIG(spi2sckPin);
|
||||
case SPI_DEVICE_3:
|
||||
return CONFIG(spi3sckPin);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return GPIO_UNASSIGNED;
|
||||
}
|
||||
|
||||
void turnOnSpi(spi_device_e device) {
|
||||
if (isSpiInitialized[device])
|
||||
return; // already initialized
|
||||
isSpiInitialized[device] = true;
|
||||
if (device == SPI_DEVICE_1) {
|
||||
// todo: introduce a nice structure with all fields for same SPI
|
||||
#if STM32_SPI_USE_SPI1
|
||||
// scheduleMsg(&logging, "Turning on SPI1 pins");
|
||||
initSpiModule(&SPID1, getSckPin(device),
|
||||
getMisoPin(device),
|
||||
getMosiPin(device),
|
||||
engineConfiguration->spi1SckMode,
|
||||
engineConfiguration->spi1MosiMode,
|
||||
engineConfiguration->spi1MisoMode);
|
||||
#endif /* STM32_SPI_USE_SPI1 */
|
||||
}
|
||||
if (device == SPI_DEVICE_2) {
|
||||
#if STM32_SPI_USE_SPI2
|
||||
// scheduleMsg(&logging, "Turning on SPI2 pins");
|
||||
initSpiModule(&SPID2, getSckPin(device),
|
||||
getMisoPin(device),
|
||||
getMosiPin(device),
|
||||
engineConfiguration->spi2SckMode,
|
||||
engineConfiguration->spi2MosiMode,
|
||||
engineConfiguration->spi2MisoMode);
|
||||
#endif /* STM32_SPI_USE_SPI2 */
|
||||
}
|
||||
if (device == SPI_DEVICE_3) {
|
||||
#if STM32_SPI_USE_SPI3
|
||||
// scheduleMsg(&logging, "Turning on SPI3 pins");
|
||||
initSpiModule(&SPID3, getSckPin(device),
|
||||
getMisoPin(device),
|
||||
getMosiPin(device),
|
||||
engineConfiguration->spi3SckMode,
|
||||
engineConfiguration->spi3MosiMode,
|
||||
engineConfiguration->spi3MisoMode);
|
||||
#endif /* STM32_SPI_USE_SPI3 */
|
||||
}
|
||||
}
|
||||
|
||||
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
|
||||
brain_pin_e mosi,
|
||||
int sckMode,
|
||||
int mosiMode,
|
||||
int misoMode) {
|
||||
|
||||
/**
|
||||
* See https://github.com/rusefi/rusefi/pull/664/
|
||||
*
|
||||
* Info on the silicon defect can be found in this document, section 2.5.2:
|
||||
* https://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM00037591.pdf/files/DM00037591.pdf/jcr:content/translations/en.DM00037591.pdf
|
||||
*/
|
||||
efiSetPadMode("SPI clock", sck, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| sckMode | PAL_STM32_OSPEED_HIGHEST*/);
|
||||
|
||||
efiSetPadMode("SPI master out", mosi, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| mosiMode | PAL_STM32_OSPEED_HIGHEST*/);
|
||||
efiSetPadMode("SPI master in ", miso, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| misoMode | PAL_STM32_OSPEED_HIGHEST*/);
|
||||
}
|
||||
|
||||
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
|
||||
spiConfig->end_cb = NULL;
|
||||
ioportid_t port = getHwPort("spi", csPin);
|
||||
ioportmask_t pin = getHwPin("spi", csPin);
|
||||
spiConfig->ssport = port;
|
||||
spiConfig->sspad = pin;
|
||||
// CS is controlled inside 'hal_spi_lld' driver using both software and hardware methods.
|
||||
//efiSetPadMode("chip select", csPin, PAL_MODE_OUTPUT_OPENDRAIN);
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_SPI */
|
||||
|
||||
BOR_Level_t BOR_Get(void) {
|
||||
return BOR_Level_None;
|
||||
}
|
||||
|
||||
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
|
||||
return BOR_Result_Ok;
|
||||
}
|
||||
|
||||
#if EFI_CAN_SUPPORT || defined(__DOXYGEN__)
|
||||
|
||||
static bool isValidCan1RxPin(brain_pin_e pin) {
|
||||
return pin == GPIOA_11 || pin == GPIOB_8 || pin == GPIOD_0;
|
||||
}
|
||||
|
||||
static bool isValidCan1TxPin(brain_pin_e pin) {
|
||||
return pin == GPIOA_12 || pin == GPIOB_9 || pin == GPIOD_1;
|
||||
}
|
||||
|
||||
static bool isValidCan2RxPin(brain_pin_e pin) {
|
||||
return pin == GPIOB_5 || pin == GPIOB_12;
|
||||
}
|
||||
|
||||
static bool isValidCan2TxPin(brain_pin_e pin) {
|
||||
return pin == GPIOB_6 || pin == GPIOB_13;
|
||||
}
|
||||
|
||||
bool isValidCanTxPin(brain_pin_e pin) {
|
||||
return isValidCan1TxPin(pin) || isValidCan2TxPin(pin);
|
||||
}
|
||||
|
||||
bool isValidCanRxPin(brain_pin_e pin) {
|
||||
return isValidCan1RxPin(pin) || isValidCan2RxPin(pin);
|
||||
}
|
||||
|
||||
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
|
||||
if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
|
||||
return &CAND1;
|
||||
if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))
|
||||
return &CAND2;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* EFI_CAN_SUPPORT */
|
||||
|
||||
size_t flashSectorSize(flashsector_t sector) {
|
||||
// sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
|
||||
if (sector <= 3 || (sector >= 12 && sector <= 15))
|
||||
return 16 * 1024;
|
||||
else if (sector == 4 || sector == 16)
|
||||
return 64 * 1024;
|
||||
else if ((sector >= 5 && sector <= 11) || (sector >= 17 && sector <= 23))
|
||||
return 128 * 1024;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* @file mpu_util.h
|
||||
*
|
||||
* @date Jul 27, 2014
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef MPU_UTIL_H_
|
||||
#define MPU_UTIL_H_
|
||||
|
||||
// we are lucky - all CAN pins use the same AF
|
||||
#define EFI_CAN_RX_AF 9
|
||||
#define EFI_CAN_TX_AF 9
|
||||
|
||||
// burnout or 'Burn Out'
|
||||
typedef enum {
|
||||
BOR_Level_None = 0,
|
||||
BOR_Level_1 = 1,
|
||||
BOR_Level_2 = 2,
|
||||
BOR_Level_3 = 3
|
||||
} BOR_Level_t;
|
||||
|
||||
typedef enum {
|
||||
BOR_Result_Ok = 0x00,
|
||||
BOR_Result_Error
|
||||
} BOR_Result_t;
|
||||
|
||||
BOR_Level_t BOR_Get(void);
|
||||
BOR_Result_t BOR_Set(BOR_Level_t BORValue);
|
||||
|
||||
#ifndef ADC_TwoSamplingDelay_5Cycles
|
||||
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
|
||||
#endif
|
||||
|
||||
#ifndef ADC_TwoSamplingDelay_20Cycles
|
||||
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
|
||||
#endif
|
||||
|
||||
#ifndef ADC_CR2_SWSTART
|
||||
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
|
||||
#endif
|
||||
|
||||
#define SPI_CR1_8BIT_MODE 0
|
||||
#define SPI_CR2_8BIT_MODE 0
|
||||
|
||||
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
|
||||
#define SPI_CR2_16BIT_MODE 0
|
||||
|
||||
// TODO
|
||||
#define SPI_CR1_24BIT_MODE 0
|
||||
#define SPI_CR2_24BIT_MODE 0
|
||||
|
||||
void baseMCUInit(void);
|
||||
void turnOnSpi(spi_device_e device);
|
||||
void jump_to_bootloader();
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
// these need to be declared C style for the linker magic to work
|
||||
|
||||
void DebugMonitorVector(void);
|
||||
void UsageFaultVector(void);
|
||||
void BusFaultVector(void);
|
||||
void HardFaultVector(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if HAL_USE_SPI
|
||||
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
|
||||
brain_pin_e mosi,
|
||||
int sckMode,
|
||||
int mosiMode,
|
||||
int misoMode);
|
||||
/**
|
||||
* @see getSpiDevice
|
||||
*/
|
||||
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
|
||||
#endif /* HAL_USE_SPI */
|
||||
|
||||
bool isValidCanTxPin(brain_pin_e pin);
|
||||
bool isValidCanRxPin(brain_pin_e pin);
|
||||
#if HAL_USE_CAN
|
||||
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
|
||||
#endif /* HAL_USE_CAN */
|
||||
|
||||
#endif /* MPU_UTIL_H_ */
|
|
@ -0,0 +1,895 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
|
||||
* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
|
||||
* *
|
||||
* This software, including source code, documentation and related *
|
||||
* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
|
||||
* one of its subsidiaries ("Cypress") and is protected by and subject to *
|
||||
* worldwide patent protection (United States and foreign), United States *
|
||||
* copyright laws and international treaty provisions. Therefore, you may use *
|
||||
* this Software only as provided in the license agreement accompanying the *
|
||||
* software package from which you obtained this Software ("EULA"). *
|
||||
* *
|
||||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
|
||||
* non-transferable license to copy, modify, and compile the *
|
||||
* Software source code solely for use in connection with Cypress's *
|
||||
* integrated circuit products. Any reproduction, modification, translation, *
|
||||
* compilation, or representation of this Software except as specified *
|
||||
* above is prohibited without the express written permission of Cypress. *
|
||||
* *
|
||||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
|
||||
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
|
||||
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. Cypress reserves the right to make *
|
||||
* changes to the Software without notice. Cypress does not assume any *
|
||||
* liability arising out of the application or use of the Software or any *
|
||||
* product or circuit described in the Software. Cypress does not *
|
||||
* authorize its products for use in any products where a malfunction or *
|
||||
* failure of the Cypress product may reasonably be expected to result in *
|
||||
* significant property damage, injury or death ("High Risk Product"). By *
|
||||
* including Cypress's product in a High Risk Product, the manufacturer *
|
||||
* of such system or application assumes all risk of such use and in doing *
|
||||
* so agrees to indemnify Cypress against all liability. *
|
||||
*******************************************************************************/
|
||||
/************************************************************************/
|
||||
/** \file usbconfig.c
|
||||
**
|
||||
** Part of USB Driver Module
|
||||
**
|
||||
** A detailed description is available at
|
||||
** @link UsbConfigGroup USB Device Cdc Com Module description @endlink
|
||||
**
|
||||
** History:
|
||||
** - 2012-08-24 2.0 MSc New Version for use with M3 L3 USB driver
|
||||
** - 2012-10-02 2.1 MSc use of external interrupts without L3 implemented
|
||||
** - 2012-11-22 2.2 MSc minor bug fixes
|
||||
** - 2015-05-05 2.3 MSCH updated to latest version, changed
|
||||
** !USB_DISBALE_..._FUNCTIONALITY to FM_PERIPHERAL_USB_..._ENABLED
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
|
||||
#include "pdl_header.h"
|
||||
#include "usb.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \defgroup UsbConfigGroup USB Config
|
||||
**
|
||||
** Provided functions of USB module:
|
||||
**
|
||||
** - UsbConfig_UsbInit()
|
||||
** - UsbConfig_SwitchMode()
|
||||
** - UsbConfig_Device0Vbus()
|
||||
** - UsbConfig_Device1Vbus()
|
||||
** - UsbConfig_Host0Overcurrent()
|
||||
** - UsbConfig_Host1Overcurrent()
|
||||
** - UsbConfig_Host0Vbus()
|
||||
** - UsbConfig_Host1Vbus()
|
||||
** - UsbConfig_Host0PulldownHostEnable()
|
||||
** - UsbConfig_Host1PulldownHostEnable()
|
||||
** - UsbDevice_Usb0ExintCallback()
|
||||
** - UsbDevice_Usb1ExintCallback()
|
||||
**
|
||||
** Used to initialize and configure the USB HAL. It gives an example how to initialize
|
||||
** all USB parts. UsbConfig_UsbInit() is used to setup USB host and device mode for USB0 and USB1.
|
||||
** UsbConfig_SwitchMode() is used to detect the Device VBUS and to do the Host / Device switching.
|
||||
** UsbConfig_Device<n>Vbus() <n = 0,1> is used to do GPIO read or write for the Device VBUS detection pin.
|
||||
** UsbConfig_Device<n>Vbus() is defined as callback for the USB stack.
|
||||
** UsbConfig_Host<n>Overcurrent() <n = 0,1> is used to do GPIO read or write for the Host overcurrent detection.
|
||||
** UsbConfig_Host<n>Overcurrent() is defined as callback for the USB stack.
|
||||
** UsbConfig_Host<n>Vbus() <n = 0,1> is used to do GPIO read or write for the Host VBUS enable.
|
||||
** UsbConfig_Host<n>Vbus() is defined as callback for the USB stack.
|
||||
** UsbConfig_Host<n>PulldownHostEnable() <n = 0,1> is used to do GPIO read or write to enable the Host 15K pulldowns (externally).
|
||||
** UsbConfig_Host<n>PulldownHostEnable() is defined as callback for the USB stack.
|
||||
** UsbDevice_Usb<n>ExintCallback() <n = 0,1> is used if the Device VBUS detection is done by IRQ.
|
||||
** UsbDevice_Usb<n>ExintCallback() is called from an external IRQ pin.
|
||||
**
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \page usbconfig_module_includes Required includes in main application
|
||||
** \brief Following includes are required
|
||||
** @code
|
||||
** #include "usb.h"
|
||||
** @endcode
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \page usbconfig_module_init Example: Initialization
|
||||
** \brief Following initialization is required
|
||||
**
|
||||
** @code
|
||||
** UsbConfig_UsbInit();
|
||||
** @endcode
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \page usbconfig_example_main Example: Whole example
|
||||
** @code
|
||||
** #include "usb.h"
|
||||
**
|
||||
**
|
||||
** int main()
|
||||
** {
|
||||
**
|
||||
** // other initializations
|
||||
**
|
||||
** UsbConfig_UsbInit();
|
||||
**
|
||||
** // other initializations
|
||||
**
|
||||
** for(;;)
|
||||
** {
|
||||
** UsbConfig_SwitchMode(); //must be called periodically to do VBUS detection
|
||||
** //or Host / Device switching
|
||||
**
|
||||
** // application code
|
||||
** }
|
||||
** }
|
||||
** @endcode
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#if ((FM_PERIPHERAL_USB_DEVICE_ENABLED == ON) || (FM_PERIPHERAL_USB_HOST_ENABLED == ON))
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
|
||||
#include "usbdevice.h"
|
||||
#if ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))
|
||||
#include "usbdevicehw.h"
|
||||
#endif
|
||||
#if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
|
||||
#include "usbdescriptors.h"
|
||||
#endif
|
||||
#endif
|
||||
#if (FM_PERIPHERAL_USB_HOST_ENABLED == ON)
|
||||
#include "usbhost.h"
|
||||
#if ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))
|
||||
#include "usbhosthw.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (USBDEVICECDCCOM_ENABLED == ON)
|
||||
#include "UsbDeviceCdcCom.h"
|
||||
#endif
|
||||
#if (USBDEVICEHIDCOM_ENABLED == ON)
|
||||
#include "UsbDeviceHidCom.h"
|
||||
#endif
|
||||
#if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
|
||||
#include "UsbDeviceHidJoystick.h"
|
||||
#endif
|
||||
#if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
|
||||
#include "UsbDeviceHidKeyboard.h"
|
||||
#endif
|
||||
#if (USBDEVICEHIDMOUSE_ENABLED == ON)
|
||||
#include "UsbDeviceHidMouse.h"
|
||||
#endif
|
||||
#if (USBDEVICELIBUSB_ENABLED == ON)
|
||||
#include "UsbDeviceLibUsb.h"
|
||||
#endif
|
||||
#if (USBDEVICEPRINTER_ENABLED == ON)
|
||||
#include "UsbDevicePrinter.h"
|
||||
#endif
|
||||
#if USBHOSTHIDMOUSE_ENABLED == ON
|
||||
#include "UsbHostHidMouse.h"
|
||||
#endif
|
||||
#if USBHOSTHIDKEYBOARD_ENABLED == ON
|
||||
#include "UsbHostHidKeyboard.h"
|
||||
#endif
|
||||
#if (USBDEVICEMASSSTORAGE_ENABLED == ON)
|
||||
#include "UsbDeviceMassStorage.h"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
/* Local pre-processor symbols/macros ('#define') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Global variable definitions (declared in header file with 'extern') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
|
||||
static void UsbConfig_UsbDeviceClassesInitCallback0(stc_usbn_t* pstcUSB);
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
|
||||
static void UsbConfig_UsbDeviceClassesInitCallback1(stc_usbn_t* pstcUSB);
|
||||
#endif
|
||||
|
||||
#ifdef __USBDEVICEHW_H__
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
static boolean_t UsbConfig_Device0Vbus(en_usb_extint_param_t enType);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
static boolean_t UsbConfig_Device1Vbus(en_usb_extint_param_t enType);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __USBHOSTHW_H__
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
boolean_t UsbConfig_Host0Overcurrent(en_usb_extint_param_t enType);
|
||||
boolean_t UsbConfig_Host0Vbus(en_usb_gpio_param_t enType);
|
||||
boolean_t UsbConfig_Host0PulldownHostEnable(en_usb_gpio_param_t enType);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
boolean_t UsbConfig_Host1Overcurrent(en_usb_extint_param_t enType);
|
||||
boolean_t UsbConfig_Host1Vbus(en_usb_gpio_param_t enType);
|
||||
boolean_t UsbConfig_Host1PulldownHostEnable(en_usb_gpio_param_t enType);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
|
||||
static void UsbConfig_UsbDeviceClassesInitCallback0(stc_usbn_t* pstcUSB)
|
||||
{
|
||||
#if (USBDEVICECDCCOM_ENABLED == ON)
|
||||
UsbDeviceCdcCom_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEHIDCOM_ENABLED == ON)
|
||||
UsbDeviceHidCom_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
|
||||
UsbDeviceHidJoystick_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
|
||||
UsbDeviceHidKeyboard_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEHIDMOUSE_ENABLED == ON)
|
||||
UsbDeviceHidMouse_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICELIBUSB_ENABLED == ON)
|
||||
UsbDeviceLibUsb_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEPRINTER_ENABLED == ON)
|
||||
UsbDevicePrinter_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
#if (USBDEVICEMASSSTORAGE_ENABLED == ON)
|
||||
UsbDeviceMassStorage_Init((stc_usbn_t*)&USB0);
|
||||
#endif
|
||||
/* USB0 WIZARD DEVICECLASSINIT */
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
|
||||
static void UsbConfig_UsbDeviceClassesInitCallback1(stc_usbn_t* pstcUSB)
|
||||
{
|
||||
#if (USBDEVICECDCCOM_ENABLED == ON)
|
||||
UsbDeviceCdcCom_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEHIDCOM_ENABLED == ON)
|
||||
UsbDeviceHidCom_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
|
||||
UsbDeviceHidJoystick_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
|
||||
UsbDeviceHidKeyboard_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEHIDMOUSE_ENABLED == ON)
|
||||
UsbDeviceHidMouse_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICELIBUSB_ENABLED == ON)
|
||||
UsbDeviceLibUsb_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEPRINTER_ENABLED == ON)
|
||||
UsbDevicePrinter_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
#if (USBDEVICEMASSSTORAGE_ENABLED == ON)
|
||||
UsbDeviceMassStorage_Init((stc_usbn_t*)&USB1);
|
||||
#endif
|
||||
/* USB1 WIZARD DEVICECLASSINIT */
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/* Global variable definitions (declared in header file with 'extern') */
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Initialize USB
|
||||
**
|
||||
******************************************************************************/
|
||||
void UsbConfig_UsbInit(void)
|
||||
{
|
||||
stc_usb_config_t stcUsbConfig;
|
||||
#if (!defined(USB_DISBALE_DEVICE_FUNCTIONALITY))
|
||||
stc_usbdevice_config_t stcUsbDeviceConfig;
|
||||
#endif
|
||||
|
||||
Usb_Init();
|
||||
|
||||
|
||||
/* Setup USB 0 */
|
||||
USB_ZERO_STRUCT(stcUsbConfig);
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
USB_ZERO_STRUCT(stcUsbDeviceConfig);
|
||||
#endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
|
||||
stcUsbConfig.enMode = UsbHostDeviceEnabled;
|
||||
#elif ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == OFF))
|
||||
stcUsbConfig.enMode = UsbHostEnabled;
|
||||
#elif ((FM_PERIPHERAL_ENABLE_USB0_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
|
||||
stcUsbConfig.enMode = UsbDeviceEnabled;
|
||||
#endif
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
#if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
|
||||
stcUsbDeviceConfig.pu8DeviceDescriptor = (uint8_t*)au8DeviceDescriptor;
|
||||
stcUsbDeviceConfig.pu8ConfigDescriptor = (uint8_t*)au8ConfigDescriptor;
|
||||
stcUsbDeviceConfig.astcReportDescriptors = (stc_usbdevice_reportdescriptor_t*)astcReportDescriptors;
|
||||
stcUsbDeviceConfig.pstcStringDescriptors = (stc_usbdevice_stringdescriptor_t*)pstcStringDescriptors;
|
||||
stcUsbDeviceConfig.u8StringDescriptorCount = USBDESCRIPTORS_STRINGDESCRIPTOR_COUNT;
|
||||
#endif /* ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1)) */
|
||||
#endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
|
||||
|
||||
stcUsbConfig.bUseInterrupts = TRUE;
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
|
||||
stcUsbConfig.pfnDeviceVbus = UsbConfig_Device0Vbus;
|
||||
#endif
|
||||
#endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
|
||||
|
||||
#if ((FM_PERIPHERAL_USB_HOST_ENABLED))
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1)))
|
||||
stcUsbConfig.pfnHostVbus = UsbConfig_Host0Vbus;
|
||||
stcUsbConfig.pfnHostPullDownHostEnable = UsbConfig_Host0PulldownHostEnable;
|
||||
stcUsbConfig.pfnHostOvercurrent = UsbConfig_Host0Overcurrent;
|
||||
#endif
|
||||
#endif /* ((FM_PERIPHERAL_USB_HOST_ENABLED)) */
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
|
||||
stcUsbDeviceConfig.pfnInitClassesCallback = UsbConfig_UsbDeviceClassesInitCallback0;
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
|
||||
UsbDevice_Init((stc_usbn_t*)&USB0,&stcUsbConfig,&stcUsbDeviceConfig);
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB0 == ON
|
||||
#if FM_PERIPHERAL_ENABLE_USB0_HOST == ON
|
||||
UsbHost_Init((stc_usbn_t*)&USB0,&stcUsbConfig);
|
||||
#endif
|
||||
Usb_Configure((stc_usbn_t*)&USB0,&stcUsbConfig);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* Setup USB 1 */
|
||||
USB_ZERO_STRUCT(stcUsbConfig);
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
USB_ZERO_STRUCT(stcUsbDeviceConfig);
|
||||
#endif
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
|
||||
stcUsbConfig.enMode = UsbHostDeviceEnabled;
|
||||
#elif ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == OFF))
|
||||
stcUsbConfig.enMode = UsbHostEnabled;
|
||||
#elif ((FM_PERIPHERAL_ENABLE_USB1_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
|
||||
stcUsbConfig.enMode = UsbDeviceEnabled;
|
||||
#endif
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
#if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
|
||||
stcUsbDeviceConfig.pu8DeviceDescriptor = (uint8_t*)au8DeviceDescriptor;
|
||||
stcUsbDeviceConfig.pu8ConfigDescriptor = (uint8_t*)au8ConfigDescriptor;
|
||||
stcUsbDeviceConfig.astcReportDescriptors = (stc_usbdevice_reportdescriptor_t*)astcReportDescriptors;
|
||||
stcUsbDeviceConfig.pstcStringDescriptors = (stc_usbdevice_stringdescriptor_t*)pstcStringDescriptors;
|
||||
stcUsbDeviceConfig.u8StringDescriptorCount = USBDESCRIPTORS_STRINGDESCRIPTOR_COUNT;
|
||||
#endif
|
||||
#endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
|
||||
|
||||
stcUsbConfig.bUseInterrupts = TRUE;
|
||||
|
||||
#if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
|
||||
stcUsbConfig.pfnDeviceVbus = UsbConfig_Device1Vbus;
|
||||
#endif
|
||||
#endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
|
||||
|
||||
#if (FM_PERIPHERAL_USB_HOST_ENABLED)
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1)))
|
||||
stcUsbConfig.pfnHostVbus = UsbConfig_Host1Vbus;
|
||||
stcUsbConfig.pfnHostPullDownHostEnable = UsbConfig_Host1PulldownHostEnable;
|
||||
stcUsbConfig.pfnHostOvercurrent = UsbConfig_Host1Overcurrent;
|
||||
#endif
|
||||
#endif /* (FM_PERIPHERAL_USB_HOST_ENABLED) */
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
|
||||
stcUsbDeviceConfig.pfnInitClassesCallback = UsbConfig_UsbDeviceClassesInitCallback1;
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
|
||||
UsbDevice_Init((stc_usbn_t*)&USB1,&stcUsbConfig,&stcUsbDeviceConfig);
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1 == ON
|
||||
#if FM_PERIPHERAL_ENABLE_USB1_HOST == ON
|
||||
UsbHost_Init((stc_usbn_t*)&USB1,&stcUsbConfig);
|
||||
#endif
|
||||
Usb_Configure((stc_usbn_t*)&USB1,&stcUsbConfig);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __USBDEVICEHW_H__
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Device 0 VBUS GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
static boolean_t UsbConfig_Device0Vbus(en_usb_extint_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbExtIntDeinit:
|
||||
DEVICE0VBUS_DEINIT;
|
||||
break;
|
||||
case UsbExtIntInit:
|
||||
DEVICE0VBUS_INIT;
|
||||
break;
|
||||
case UsbExtIntDisableIsr:
|
||||
DEVICE0VBUS_DISABLEISR;
|
||||
break;
|
||||
case UsbExtIntEnableIsr:
|
||||
DEVICE0VBUS_ENABLEISR;
|
||||
break;
|
||||
case UsbExtIntClearIsrFlag:
|
||||
DEVICE0VBUS_CLEARISRFLAG;
|
||||
break;
|
||||
case UsbExtIntIsSetIsrFlag:
|
||||
return DEVICE0VBUS_ISRISSET;
|
||||
case UsbExtIntSetLowDetect:
|
||||
DEVICE0VBUS_SETLOWDETECT;
|
||||
break;
|
||||
case UsbExtIntSetHighDetect:
|
||||
DEVICE0VBUS_SETHIGHDETECT;
|
||||
break;
|
||||
case UsbExtIntGetLevel:
|
||||
return DEVICE0VBUS_HIGHDETECT;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Device 1 VBUS GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
static boolean_t UsbConfig_Device1Vbus(en_usb_extint_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbExtIntDeinit:
|
||||
DEVICE1VBUS_DEINIT;
|
||||
break;
|
||||
case UsbExtIntInit:
|
||||
DEVICE1VBUS_INIT;
|
||||
break;
|
||||
case UsbExtIntDisableIsr:
|
||||
DEVICE1VBUS_DISABLEISR;
|
||||
break;
|
||||
case UsbExtIntEnableIsr:
|
||||
DEVICE1VBUS_ENABLEISR;
|
||||
break;
|
||||
case UsbExtIntClearIsrFlag:
|
||||
DEVICE1VBUS_CLEARISRFLAG;
|
||||
break;
|
||||
case UsbExtIntIsSetIsrFlag:
|
||||
return DEVICE1VBUS_ISRISSET;
|
||||
break;
|
||||
case UsbExtIntSetLowDetect:
|
||||
DEVICE1VBUS_SETLOWDETECT;
|
||||
break;
|
||||
case UsbExtIntSetHighDetect:
|
||||
DEVICE1VBUS_SETHIGHDETECT;
|
||||
break;
|
||||
case UsbExtIntGetLevel:
|
||||
return DEVICE1VBUS_HIGHDETECT;
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __USBHOSTHW_H__
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 0 Overcurrent GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host0Overcurrent(en_usb_extint_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbExtIntDeinit:
|
||||
HOST0OVERCURRENT_DEINIT;
|
||||
break;
|
||||
case UsbExtIntInit:
|
||||
HOST0OVERCURRENT_INIT;
|
||||
break;
|
||||
case UsbExtIntDisableIsr:
|
||||
HOST0OVERCURRENT_DISABLEISR;
|
||||
break;
|
||||
case UsbExtIntEnableIsr:
|
||||
HOST0OVERCURRENT_ENABLEISR;
|
||||
break;
|
||||
case UsbExtIntClearIsrFlag:
|
||||
HOST0OVERCURRENT_CLEARISRFLAG;
|
||||
break;
|
||||
case UsbExtIntIsSetIsrFlag:
|
||||
return HOST0OVERCURRENT_ISRISSET;
|
||||
case UsbExtIntSetLowDetect:
|
||||
HOST0OVERCURRENT_SETLOWDETECT;
|
||||
break;
|
||||
case UsbExtIntSetHighDetect:
|
||||
HOST0OVERCURRENT_SETHIGHDETECT;
|
||||
break;
|
||||
case UsbExtIntGetLevel:
|
||||
return HOST0OVERCURRENT_HIGHDETECT;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 0 VBUS GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host0Vbus(en_usb_gpio_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbGpioDeinit:
|
||||
HOST0VBUS_DEINIT;
|
||||
break;
|
||||
case UsbGpioInit:
|
||||
HOST0VBUS_INIT;
|
||||
break;
|
||||
case UsbGpioSet:
|
||||
HOST0VBUS_SET;
|
||||
break;
|
||||
case UsbGpioClear:
|
||||
HOST0VBUS_CLEAR;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 0 pull-down GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host0PulldownHostEnable(en_usb_gpio_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbGpioDeinit:
|
||||
HOST0OTGPULLDOWN_DEINIT;
|
||||
break;
|
||||
case UsbGpioInit:
|
||||
HOST0OTGPULLDOWN_INIT;
|
||||
break;
|
||||
case UsbGpioSet:
|
||||
HOST0OTGPULLDOWN_SET;
|
||||
break;
|
||||
case UsbGpioClear:
|
||||
HOST0OTGPULLDOWN_CLEAR;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 1 Overcurrent GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host1Overcurrent(en_usb_extint_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbExtIntDeinit:
|
||||
HOST1OVERCURRENT_DEINIT;
|
||||
break;
|
||||
case UsbExtIntInit:
|
||||
HOST1OVERCURRENT_INIT;
|
||||
break;
|
||||
case UsbExtIntDisableIsr:
|
||||
HOST1OVERCURRENT_DISABLEISR;
|
||||
break;
|
||||
case UsbExtIntEnableIsr:
|
||||
HOST1OVERCURRENT_ENABLEISR;
|
||||
break;
|
||||
case UsbExtIntClearIsrFlag:
|
||||
HOST1OVERCURRENT_CLEARISRFLAG;
|
||||
break;
|
||||
case UsbExtIntIsSetIsrFlag:
|
||||
return HOST1OVERCURRENT_ISRISSET;
|
||||
case UsbExtIntSetLowDetect:
|
||||
HOST1OVERCURRENT_SETLOWDETECT;
|
||||
break;
|
||||
case UsbExtIntSetHighDetect:
|
||||
HOST1OVERCURRENT_SETHIGHDETECT;
|
||||
break;
|
||||
case UsbExtIntGetLevel:
|
||||
return HOST1OVERCURRENT_HIGHDETECT;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 1 VBUS GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host1Vbus(en_usb_gpio_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbGpioDeinit:
|
||||
HOST1VBUS_DEINIT;
|
||||
break;
|
||||
case UsbGpioInit:
|
||||
HOST1VBUS_INIT;
|
||||
break;
|
||||
case UsbGpioSet:
|
||||
HOST1VBUS_SET;
|
||||
break;
|
||||
case UsbGpioClear:
|
||||
HOST1VBUS_CLEAR;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Host 1 pull-down GPIO / external interrupt callback
|
||||
**
|
||||
** \param enType
|
||||
**
|
||||
** \return Depending on enType
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t UsbConfig_Host1PulldownHostEnable(en_usb_gpio_param_t enType)
|
||||
{
|
||||
switch(enType)
|
||||
{
|
||||
case UsbGpioDeinit:
|
||||
HOST1OTGPULLDOWN_DEINIT;
|
||||
break;
|
||||
case UsbGpioInit:
|
||||
HOST1OTGPULLDOWN_INIT;
|
||||
break;
|
||||
case UsbGpioSet:
|
||||
HOST1OTGPULLDOWN_SET;
|
||||
break;
|
||||
case UsbGpioClear:
|
||||
HOST1OTGPULLDOWN_CLEAR;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
void UsbConfig_SwitchMode(void)
|
||||
{
|
||||
#if FM_PERIPHERAL_ENABLE_USB0 == ON
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == OFF))
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchToHost,0);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if FM_PERIPHERAL_ENABLE_USB1 == ON
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == OFF))
|
||||
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchToHost,0);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0);
|
||||
#endif
|
||||
#if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
|
||||
Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON)
|
||||
void UsbDevice_Usb0ExintCallback(void)
|
||||
{
|
||||
if (Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0) == Ok)
|
||||
{
|
||||
if (DEVICE0VBUS_HIGHDETECT)
|
||||
{
|
||||
DEVICE0VBUS_SETLOWDETECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEVICE0VBUS_SETHIGHDETECT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON)
|
||||
void UsbDevice_Usb1ExintCallback(void)
|
||||
{
|
||||
if (Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0) == Ok)
|
||||
{
|
||||
if (DEVICE1VBUS_HIGHDETECT)
|
||||
{
|
||||
DEVICE1VBUS_SETLOWDETECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEVICE1VBUS_SETHIGHDETECT;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if (USB_USE_L3 == 0)
|
||||
#if ((USB_USE_L3 == 0) && (USB_USE_EXT_INT == 1))
|
||||
#if (!defined(USB_DISBALE_DEVICE_FUNCTIONALITY))
|
||||
void INT8_31_Handler (void)
|
||||
{
|
||||
#if FM_PERIPHERAL_ENABLE_USB0 == ON
|
||||
if (DEVICE0VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE0VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb0ExintCallback();
|
||||
}
|
||||
#endif
|
||||
#if FM_PERIPHERAL_ENABLE_USB1 == ON
|
||||
if (DEVICE1VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE1VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb1ExintCallback();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void INT8_15_Handler (void)
|
||||
{
|
||||
#if FM_PERIPHERAL_ENABLE_USB0 == ON
|
||||
if (DEVICE0VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE0VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb0ExintCallback();
|
||||
}
|
||||
#endif
|
||||
#if FM_PERIPHERAL_ENABLE_USB1 == ON
|
||||
if (DEVICE1VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE1VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb1ExintCallback();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void INT0_7_Handler (void)
|
||||
{
|
||||
#if FM_PERIPHERAL_ENABLE_USB0 == ON
|
||||
if (DEVICE0VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE0VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb0ExintCallback();
|
||||
}
|
||||
#endif
|
||||
#if FM_PERIPHERAL_ENABLE_USB1 == ON
|
||||
if (DEVICE1VBUS_ISRISSET)
|
||||
{
|
||||
DEVICE1VBUS_CLEARISRFLAG;
|
||||
UsbDevice_Usb1ExintCallback();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Initialize USB (dummy if USB is disabled)
|
||||
**
|
||||
******************************************************************************/
|
||||
void UsbConfig_UsbInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Switch USB mode (dummy if USB is disabled)
|
||||
**
|
||||
******************************************************************************/
|
||||
void UsbConfig_SwitchMode(void)
|
||||
{
|
||||
}
|
||||
#endif /* ((!defined(USB_DISBALE_DEVICE_FUNCTIONALITY)) || (!defined(USB_DISBALE_HOST_FUNCTIONALITY))) */
|
||||
//@} // UsbConfigGroup
|
|
@ -0,0 +1,266 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
|
||||
* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
|
||||
* *
|
||||
* This software, including source code, documentation and related *
|
||||
* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
|
||||
* one of its subsidiaries ("Cypress") and is protected by and subject to *
|
||||
* worldwide patent protection (United States and foreign), United States *
|
||||
* copyright laws and international treaty provisions. Therefore, you may use *
|
||||
* this Software only as provided in the license agreement accompanying the *
|
||||
* software package from which you obtained this Software ("EULA"). *
|
||||
* *
|
||||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
|
||||
* non-transferable license to copy, modify, and compile the *
|
||||
* Software source code solely for use in connection with Cypress's *
|
||||
* integrated circuit products. Any reproduction, modification, translation, *
|
||||
* compilation, or representation of this Software except as specified *
|
||||
* above is prohibited without the express written permission of Cypress. *
|
||||
* *
|
||||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
|
||||
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
|
||||
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. Cypress reserves the right to make *
|
||||
* changes to the Software without notice. Cypress does not assume any *
|
||||
* liability arising out of the application or use of the Software or any *
|
||||
* product or circuit described in the Software. Cypress does not *
|
||||
* authorize its products for use in any products where a malfunction or *
|
||||
* failure of the Cypress product may reasonably be expected to result in *
|
||||
* significant property damage, injury or death ("High Risk Product"). By *
|
||||
* including Cypress's product in a High Risk Product, the manufacturer *
|
||||
* of such system or application assumes all risk of such use and in doing *
|
||||
* so agrees to indemnify Cypress against all liability. *
|
||||
*******************************************************************************/
|
||||
/******************************************************************************/
|
||||
/** \file usbconfig.h
|
||||
**
|
||||
** Part of FSEU USB Driver Module
|
||||
**
|
||||
** History:
|
||||
** - 2012-07-17 2.0 MSc New Version for use with M3 L3 USB driver
|
||||
** - 2012-10-02 2.1 MSc use of external interrupts without L3 implemented
|
||||
** - 2012-01-31 2.2 MSc DMA settings added
|
||||
** - 2013-06-04 2.3 MSc FM4 support added
|
||||
** - 2013-09-23 2.4 MSc Version for PDL
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __USBCONFIG_H__
|
||||
#define __USBCONFIG_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global pre-processor symbols/macros ('#define') */
|
||||
/*****************************************************************************/
|
||||
|
||||
//-------- <<< Use Configuration Wizard in Context Menu>>> -----------------
|
||||
// <h>USB Debug
|
||||
// =======================
|
||||
//
|
||||
// <o>Use USB debug functionality via UART
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USEUSBDBG
|
||||
#define USEUSBDBG 0
|
||||
#endif
|
||||
|
||||
// <o>Precompiler Warning Level
|
||||
// <0=> no warnings
|
||||
// <1=> hard warnings
|
||||
// <2=> all warnings
|
||||
#ifndef USBWARNLEVEL
|
||||
#define USBWARNLEVEL 0 //0: no warnings, 1: hard warnings, 2: all warnings
|
||||
#endif
|
||||
// </h>
|
||||
|
||||
// <h>Use of Headerfiles
|
||||
// =======================
|
||||
//
|
||||
// <o>Use usbdescriptors.h
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USE_USBDESCRIPTORS_H
|
||||
#define USE_USBDESCRIPTORS_H 1 //<- 1 use usbdescriptors.h file for USB descriptors settings, 0 for disabling
|
||||
#endif
|
||||
|
||||
// <o>Use usbdevicehw.h
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USE_USBDEVICEHW_H
|
||||
#define USE_USBDEVICEHW_H 1 //<- 1 use usbdevicehw.h file for gpio settings, 0 for disabling
|
||||
#endif
|
||||
|
||||
// <o>Use usbhosthw.h
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USE_USBHOSTHW_H
|
||||
#define USE_USBHOSTHW_H 1 //<- 1 use usbhosthw.h file for gpio settings, 0 for disabling
|
||||
#endif
|
||||
|
||||
// <o>Use sbhostclassdrivertable.h
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USE_USBHOSTCLASSDRIVERTABLE_H
|
||||
#define USE_USBHOSTCLASSDRIVERTABLE_H 0 //<- 1 use usbhostclassdrivertable.h file
|
||||
#endif
|
||||
// </h>
|
||||
|
||||
// <h>Use USB within a low level library
|
||||
// =======================
|
||||
//
|
||||
// <o>Use with L3 (old library for FM3 MCUs)
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USB_USE_L3
|
||||
#define USB_USE_L3 0 //<- 1 use as part of L3 library, 0 for using without L3 library
|
||||
#endif
|
||||
|
||||
// <o>Use with PDL
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#define USB_USE_PDL 0 //<- 1 use as part of PDL library, 0 for using without PDL library
|
||||
//</h>
|
||||
|
||||
|
||||
#if (USB_USE_PDL == 0) && (USB_USE_L3 == 0)
|
||||
/* START Middleware Modules */
|
||||
|
||||
/* DEVICE */
|
||||
// <h>USB Device middleware modules
|
||||
// =======================
|
||||
//
|
||||
// <o>USB Device CDC
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICECDCCOM_ENABLED
|
||||
#define USBDEVICECDCCOM_ENABLED ON //Middleware USB CDC Communication Class
|
||||
#endif
|
||||
|
||||
// <o>USB Device HID (data communication)
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEHIDCOM_ENABLED
|
||||
#define USBDEVICEHIDCOM_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device HID Joystick
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEHIDJOYSTICK_ENABLED
|
||||
#define USBDEVICEHIDJOYSTICK_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device HID Keyboard
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEHIDKEYBOARD_ENABLED
|
||||
#define USBDEVICEHIDKEYBOARD_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device HID Mouse
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEHIDMOUSE_ENABLED
|
||||
#define USBDEVICEHIDMOUSE_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device LibUSB
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICELIBUSB_ENABLED
|
||||
#define USBDEVICELIBUSB_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device Printer
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEPRINTER_ENABLED
|
||||
#define USBDEVICEPRINTER_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Device Mass Storage
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBDEVICEMASSSTORAGE_ENABLED
|
||||
#define USBDEVICEMASSSTORAGE_ENABLED OFF
|
||||
#endif
|
||||
//</h>
|
||||
|
||||
|
||||
|
||||
/* HOST */
|
||||
// <h>USB Host middleware modules
|
||||
// =======================
|
||||
//
|
||||
// <o>USB Host HID (Data communication)
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTHIDCOM_ENABLED
|
||||
#define USBHOSTHIDCOM_ENABLED OFF
|
||||
#endif
|
||||
|
||||
// <o>USB Host HID Keyboard
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTHIDKEYBOARD_ENABLED
|
||||
#define USBHOSTHIDKEYBOARD_ENABLED OFF /* [andreika] */
|
||||
#endif
|
||||
|
||||
// <o>USB Host HID Mouse
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTHIDMOUSE_ENABLED
|
||||
#define USBHOSTHIDMOUSE_ENABLED OFF /* [andreika] */
|
||||
#endif
|
||||
|
||||
// <o>USB Host Mass Storage
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTMASSSTORAGE_ENABLED
|
||||
#define USBHOSTMASSSTORAGE_ENABLED OFF /* [andreika] */
|
||||
#endif
|
||||
|
||||
// <o>USB Host NDIS
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTNDIS_ENABLED
|
||||
#define USBHOSTNDIS_ENABLED OFF /* [andreika] */
|
||||
#endif
|
||||
|
||||
// <o>USB Host Printer
|
||||
// <0=> OFF
|
||||
// <1=> ON
|
||||
#ifndef USBHOSTPRINTER_ENABLED
|
||||
#define USBHOSTPRINTER_ENABLED OFF /* [andreika] */
|
||||
#endif
|
||||
//</h>
|
||||
|
||||
/* END Middleware Modules */
|
||||
|
||||
/* only used if USB is used without L3 or PDL*/
|
||||
#define USB0_HOST_ENABLED 0
|
||||
#define USB0_DEVICE_ENABLED 1
|
||||
#define USB1_HOST_ENABLED 0
|
||||
#define USB1_DEVICE_ENABLED 0
|
||||
#define USB0_DEVICE_IRQ_ENABLED 1
|
||||
#define USB0_HOST_IRQ_ENABLED 1
|
||||
#define USB1_DEVICE_IRQ_ENABLED 1
|
||||
#define USB1_HOST_IRQ_ENABLED 1
|
||||
#define USB_USE_EXT_INT 0
|
||||
#define IRQ_LEVEL_USB0 3
|
||||
#define IRQ_LEVEL_USB1 3
|
||||
#define USB_USES_DMA 0
|
||||
#define USB_USES_DMA_0 1
|
||||
#define USB_USES_DMA_1 1
|
||||
#define USB_USES_DMA_2 0
|
||||
#define USB_USES_DMA_3 0
|
||||
#define USB_USES_DMA_4 0
|
||||
#define USB_USES_DMA_5 0
|
||||
#define USB_USES_DMA_6 0
|
||||
#define USB_USES_DMA_7 0
|
||||
|
||||
#endif //(USB_USE_PDL == 0) && (USB_USE_L3 == 0)
|
||||
|
||||
void UsbConfig_UsbInit(void);
|
||||
void UsbConfig_SwitchMode(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,170 @@
|
|||
#include "global.h"
|
||||
#include "os_access.h"
|
||||
|
||||
#if EFI_USB_SERIAL
|
||||
|
||||
#include "pdl_header.h"
|
||||
#include "usb.h"
|
||||
#include "UsbDeviceCdcCom.h"
|
||||
|
||||
// 10 seconds
|
||||
#define USB_WRITE_TIMEOUT 10000
|
||||
|
||||
// See uart_dma_s
|
||||
#define USB_FIFO_BUFFER_SIZE (BLOCKING_FACTOR + 30)
|
||||
|
||||
// struct needed for async transfer mode
|
||||
typedef struct {
|
||||
// secondary FIFO buffer for async. transfer
|
||||
uint8_t buffer[USB_FIFO_BUFFER_SIZE];
|
||||
// input FIFO Rx queue
|
||||
input_queue_t fifoRxQueue;
|
||||
} usb_buf_s;
|
||||
|
||||
static usb_buf_s usbBuf;
|
||||
|
||||
|
||||
static bool isUsbSerialInitialized = false;
|
||||
|
||||
static bool isUsbSerialInitStarted = false;
|
||||
|
||||
static thread_reference_t threadrx = NULL;
|
||||
|
||||
// called from the USB IRQ handler
|
||||
static void onUsbDataReceived(uint8_t* pu8Data, uint32_t u32ReceviedSize) {
|
||||
osalSysLockFromISR();
|
||||
|
||||
// copy the data to the FIFO buffer
|
||||
for (int i = 0; i < u32ReceviedSize; i++) {
|
||||
if (iqPutI(&usbBuf.fifoRxQueue, *pu8Data++) != Q_OK) {
|
||||
break; // todo: ignore overflow?
|
||||
}
|
||||
}
|
||||
|
||||
// tell the reader thread to wake up
|
||||
#if 0
|
||||
if (threadrx != NULL) {
|
||||
osalThreadResumeI(&threadrx, MSG_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
osalSysUnlockFromISR();
|
||||
}
|
||||
|
||||
// To use UART driver instead of Serial, we need to imitate "BaseChannel" streaming functionality
|
||||
static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) {
|
||||
(void)ip;
|
||||
(void)timeout;
|
||||
UsbDeviceCdcCom_SendByte(b);
|
||||
return MSG_OK;
|
||||
}
|
||||
static size_t _writet(void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout) {
|
||||
(void)ip;
|
||||
(void)timeout;
|
||||
UsbDeviceCdcCom_SendBuffer((uint8_t *)bp, n);
|
||||
return n;
|
||||
}
|
||||
static msg_t _put(void *ip, uint8_t b) {
|
||||
(void)ip;
|
||||
UsbDeviceCdcCom_SendByte(b);
|
||||
/*
|
||||
// uartSendTimeout() needs interrupts to wait for the end of transfer, so we have to unlock them temporary
|
||||
bool wasLocked = isLocked();
|
||||
if (wasLocked)
|
||||
unlockAnyContext();
|
||||
_putt(ip, b, CONSOLE_WRITE_TIMEOUT);
|
||||
if (wasLocked)
|
||||
lockAnyContext();
|
||||
*/
|
||||
return MSG_OK;
|
||||
}
|
||||
static size_t _write(void *ip, const uint8_t *bp, size_t n) {
|
||||
return _writet(ip, bp, n, USB_WRITE_TIMEOUT);
|
||||
}
|
||||
static size_t _readt(void *ip, uint8_t *bp, size_t n, sysinterval_t timeout) {
|
||||
size_t numBytesRead;
|
||||
//numBytesRead = UsbDeviceCdcCom_ReceiveBuffer(bp, n);
|
||||
|
||||
return (size_t)iqReadTimeout(&usbBuf.fifoRxQueue, bp, n, timeout);
|
||||
/*
|
||||
// if we don't have all bytes immediately
|
||||
if (numBytesRead < n) {
|
||||
osalSysLock();
|
||||
threadrx = chThdGetSelfX();
|
||||
osalThreadSuspendTimeoutS(&threadrx, timeout);
|
||||
osalSysUnlock();
|
||||
numBytesRead += UsbDeviceCdcCom_ReceiveBuffer(bp + numBytesRead, n - numBytesRead);
|
||||
}
|
||||
return numBytesRead;
|
||||
*/
|
||||
}
|
||||
static msg_t _gett(void *ip, sysinterval_t timeout) {
|
||||
(void)ip;
|
||||
(void)timeout;
|
||||
//msg_t msg = UsbDeviceCdcCom_ReceiveByte();
|
||||
uint8_t b;
|
||||
if (_readt(ip, &b, 1, timeout) == 1)
|
||||
return (msg_t)b;
|
||||
return MSG_TIMEOUT;
|
||||
}
|
||||
static msg_t _get(void *ip) {
|
||||
return _gett(ip, USB_WRITE_TIMEOUT);
|
||||
}
|
||||
static size_t _read(void *ip, uint8_t *bp, size_t n) {
|
||||
(void)ip;
|
||||
return _readt(ip, bp, n, USB_WRITE_TIMEOUT);
|
||||
}
|
||||
static msg_t _ctl(void *ip, unsigned int operation, void *arg) {
|
||||
return MSG_OK;
|
||||
}
|
||||
|
||||
// This is a "fake" channel for getConsoleChannel() filled with our handlers
|
||||
static const struct BaseChannelVMT usbChannelVmt = {
|
||||
.instance_offset = (size_t)0, .write = _write, .read = _read, .put = _put, .get = _get,
|
||||
.putt = _putt, .gett = _gett, .writet = _writet, .readt = _readt, .ctl = _ctl
|
||||
};
|
||||
|
||||
BaseChannel SDU1 = { .vmt = &usbChannelVmt };
|
||||
|
||||
|
||||
static void usb_VBus_handler(uint8_t channel) {
|
||||
// call it only if the USB driver is already initialized
|
||||
if (isUsbSerialInitialized)
|
||||
UsbConfig_SwitchMode();
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief Main function of PDL
|
||||
**
|
||||
** \return uint32_t return value, if needed
|
||||
******************************************************************************/
|
||||
void usb_serial_start(void) {
|
||||
if (isUsbSerialInitStarted)
|
||||
return;
|
||||
|
||||
isUsbSerialInitStarted = true;
|
||||
|
||||
UsbConfig_UsbInit();
|
||||
|
||||
// init FIFO queue
|
||||
iqObjectInit(&usbBuf.fifoRxQueue, usbBuf.buffer, sizeof(usbBuf.buffer), NULL, NULL);
|
||||
|
||||
UsbDeviceCdcCom_SetReceivedCallback(onUsbDataReceived);
|
||||
|
||||
UsbConfig_SwitchMode();
|
||||
|
||||
// init VBus detector for P60 (INT31_0)
|
||||
SetPinFunc_INT31_0(0u);
|
||||
_pal_lld_setpadeventhandler(31, ExIntRisingEdge, usb_VBus_handler);
|
||||
|
||||
|
||||
isUsbSerialInitialized = true;
|
||||
|
||||
}
|
||||
|
||||
bool is_usb_serial_ready(void) {
|
||||
return isUsbSerialInitialized /*&& SDU1.config->usbp->state == USB_ACTIVE*/;
|
||||
}
|
||||
|
||||
#endif /* EFI_USB_SERIAL */
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* @file usbconsole.h
|
||||
*
|
||||
* @date Jan 27, 2020
|
||||
* @author andreika <prometheus.pcb@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef USBCONSOLE_H_
|
||||
#define USBCONSOLE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void usb_serial_start(void);
|
||||
bool is_usb_serial_ready(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* USBCONSOLE_H_ */
|
|
@ -0,0 +1,190 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
|
||||
* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
|
||||
* *
|
||||
* This software, including source code, documentation and related *
|
||||
* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
|
||||
* one of its subsidiaries ("Cypress") and is protected by and subject to *
|
||||
* worldwide patent protection (United States and foreign), United States *
|
||||
* copyright laws and international treaty provisions. Therefore, you may use *
|
||||
* this Software only as provided in the license agreement accompanying the *
|
||||
* software package from which you obtained this Software ("EULA"). *
|
||||
* *
|
||||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
|
||||
* non-transferable license to copy, modify, and compile the *
|
||||
* Software source code solely for use in connection with Cypress's *
|
||||
* integrated circuit products. Any reproduction, modification, translation, *
|
||||
* compilation, or representation of this Software except as specified *
|
||||
* above is prohibited without the express written permission of Cypress. *
|
||||
* *
|
||||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
|
||||
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
|
||||
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. Cypress reserves the right to make *
|
||||
* changes to the Software without notice. Cypress does not assume any *
|
||||
* liability arising out of the application or use of the Software or any *
|
||||
* product or circuit described in the Software. Cypress does not *
|
||||
* authorize its products for use in any products where a malfunction or *
|
||||
* failure of the Cypress product may reasonably be expected to result in *
|
||||
* significant property damage, injury or death ("High Risk Product"). By *
|
||||
* including Cypress's product in a High Risk Product, the manufacturer *
|
||||
* of such system or application assumes all risk of such use and in doing *
|
||||
* so agrees to indemnify Cypress against all liability. *
|
||||
*******************************************************************************/
|
||||
/******************************************************************************/
|
||||
/** \file UsbDescriptors.h
|
||||
**
|
||||
** USB Descriptors File
|
||||
**
|
||||
** History:
|
||||
** - 2020-1-27 1.0 MSc Automatically Created by Spansion USB Wizard
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __USBDESCRIPTORS_H__
|
||||
#define __USBDESCRIPTORS_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Include files */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global pre-processor symbols/macros ('#define') */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define USB_DEVDESC_SIZE 18
|
||||
#define USB_CNFGDESC_SIZE 53
|
||||
#define USB_FUNC_EP0_SIZE 64
|
||||
#define CLASSNAME "UsbDeviceCdcCom"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global type definitions ('typedef') */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define USBDESCRIPTORS_STRINGDESCRIPTOR_COUNT (uint32_t)(sizeof(pstcStringDescriptors) / sizeof(pstcStringDescriptors[0]))
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variable declarations ('extern', definition in C source) */
|
||||
/*****************************************************************************/
|
||||
// [andreika]: use ST-compatible vendor+product IDs
|
||||
const uint8_t au8DeviceDescriptor[18] =
|
||||
{
|
||||
///DEVICE DESCRIPTOR
|
||||
0x12, ///bLength: Length of this descriptor
|
||||
0x01, ///bDescriptorType: Device Descriptor Type
|
||||
0x10, ///bcdUSB: USB Version
|
||||
0x01, ///bcdUSB: USB Version
|
||||
0x02, ///bDeviceClass: Class Code: COMMUNICATIONS_AND_CDC_CONTROL
|
||||
0x00, ///bDeviceSubClass: Sub Class Code
|
||||
0x00, ///bDeviceProtocol: Protocol Code
|
||||
0x40, ///bMaxPacketSize0: Maximum size of endpoint 0
|
||||
0x83, ///idVendor: Vendor ID
|
||||
0x04, ///idVendor: Vendor ID
|
||||
0x40, ///idProduct: Product ID
|
||||
0x57, ///idProduct: Product ID
|
||||
0x00, ///bcdDevice: Release Number
|
||||
0x02, ///bcdDevice: Release Number
|
||||
0x01, ///iManufacture: String-Index of Manufacture
|
||||
0x02, ///iProduct: String-Index of Product
|
||||
0x03, ///iSerialNumber: String-Index of Serial Number
|
||||
0x01 ///bNumConfigurations: Number of possible configurations
|
||||
};
|
||||
|
||||
const uint8_t au8ConfigDescriptor[53] =
|
||||
{ ///NEW CONFIG DESCRIPTOR(1)
|
||||
0x09, ///bLength: Length of this descriptor
|
||||
0x02, ///bDescriptorType: Config Descriptor Type
|
||||
0x35, ///wTotalLength: Total Length with all interface- and endpoint descriptors
|
||||
0x00, ///wTotalLength: Total Length with all interface- and endpoint descriptors
|
||||
0x02, ///bNumInterfaces: Number of interfaces
|
||||
0x01, ///iConfigurationValue: Number of this configuration
|
||||
0x00, ///iConfiguration: String index of this configuration
|
||||
0xC0, ///bmAttributes: Bus-Powered, Remote-Wakeup not supported
|
||||
0xFA, ///MaxPower: (in 2mA)
|
||||
///NEW INTERFACE DESCRIPTOR(0)
|
||||
0x09, ///bLength: Length of this descriptor
|
||||
0x04, ///bDescriptorType: Interface Descriptor Type
|
||||
0x00, ///bInterfaceNumber: Interface Number
|
||||
0x00, ///bAlternateSetting: Alternate setting for this interface
|
||||
0x01, ///bNumEndpoints: Number of endpoints in this interface excluding endpoint 0
|
||||
0x02, ///iInterfaceClass: Class Code: COMMUNICATIONS_AND_CDC_CONTROL
|
||||
0x02, ///iInterfaceSubClass: SubClass Code
|
||||
0x01, ///bInterfaceProtocol: Protocol Code
|
||||
0x00, ///iInterface: String index
|
||||
///NEW FUNCTION DESCRIPTOR(0)
|
||||
0x05, ///bLength: Length of this descriptor
|
||||
0x24, ///bDescriptorType: Class Specific Interface Descriptor Type
|
||||
0x06, ///bDescriptorSubtype: Union Functional descriptor
|
||||
0x00, ///Master Interface (Control)
|
||||
0x01, ///Slave Interface (Data)
|
||||
///NEW ENDPOINT DESCRIPTOR(1)
|
||||
0x07, ///bLength: Length of this descriptor
|
||||
0x05, ///bDescriptorType: Endpoint Descriptor Type
|
||||
0x82, ///bEndpointAddress: Endpoint address (IN,EP2)
|
||||
0x03, ///bmAttributes: Transfer Type: INTERRUPT_TRANSFER
|
||||
0x40, ///wMaxPacketSize: Endpoint Size
|
||||
0x00, ///wMaxPacketSize: Endpoint Size
|
||||
0xFF, ///bIntervall: Polling Intervall
|
||||
///NEW INTERFACE DESCRIPTOR(1)
|
||||
0x09, ///bLength: Length of this descriptor
|
||||
0x04, ///bDescriptorType: Interface Descriptor Type
|
||||
0x01, ///bInterfaceNumber: Interface Number
|
||||
0x00, ///bAlternateSetting: Alternate setting for this interface
|
||||
0x02, ///bNumEndpoints: Number of endpoints in this interface excluding endpoint 0
|
||||
0x0A, ///iInterfaceClass: Class Code: CDC_DATA
|
||||
0x00, ///iInterfaceSubClass: SubClass Code
|
||||
0x00, ///bInterfaceProtocol: Protocol Code
|
||||
0x00, ///iInterface: String index
|
||||
///NEW ENDPOINT DESCRIPTOR(0)
|
||||
0x07, ///bLength: Length of this descriptor
|
||||
0x05, ///bDescriptorType: Endpoint Descriptor Type
|
||||
0x03, ///bEndpointAddress: Endpoint address (OUT,EP3)
|
||||
0x02, ///bmAttributes: Transfer Type: BULK_TRANSFER
|
||||
0x40, ///wMaxPacketSize: Endpoint Size
|
||||
0x00, ///wMaxPacketSize: Endpoint Size
|
||||
0x00, ///bIntervall: Polling Intervall
|
||||
///NEW ENDPOINT DESCRIPTOR(1)
|
||||
0x07, ///bLength: Length of this descriptor
|
||||
0x05, ///bDescriptorType: Endpoint Descriptor Type
|
||||
0x81, ///bEndpointAddress: Endpoint address (IN,EP1)
|
||||
0x02, ///bmAttributes: Transfer Type: BULK_TRANSFER
|
||||
0x40, ///wMaxPacketSize: Endpoint Size
|
||||
0x00, ///wMaxPacketSize: Endpoint Size
|
||||
0x00 ///bIntervall: Polling Intervall
|
||||
};
|
||||
|
||||
const uint8_t au8ReportDescriptor0[1]; // Not used
|
||||
const uint8_t au8ReportDescriptor1[1]; // Not used
|
||||
const uint8_t au8ReportDescriptor2[1]; // Not used
|
||||
|
||||
|
||||
const stc_usbdevice_stringdescriptor_t pstcStringDescriptors[] =
|
||||
{
|
||||
{"Spansion International Inc.",NULL}, //Manufacturer String
|
||||
{"rusEFI ECU Comm Port",NULL}, //Product String
|
||||
{"1.0",NULL}, //Serial Number String
|
||||
};
|
||||
|
||||
|
||||
const stc_usbdevice_reportdescriptor_t astcReportDescriptors[3] =
|
||||
{
|
||||
{(uint8_t*)au8ReportDescriptor0,sizeof(au8ReportDescriptor0)},
|
||||
{(uint8_t*)au8ReportDescriptor1,sizeof(au8ReportDescriptor1)},
|
||||
{(uint8_t*)au8ReportDescriptor2,sizeof(au8ReportDescriptor2)},
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global function prototypes ('extern', definition in C source) */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __USBDESCRIPTORS_H__ */
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
|
||||
* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
|
||||
* *
|
||||
* This software, including source code, documentation and related *
|
||||
* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
|
||||
* one of its subsidiaries ("Cypress") and is protected by and subject to *
|
||||
* worldwide patent protection (United States and foreign), United States *
|
||||
* copyright laws and international treaty provisions. Therefore, you may use *
|
||||
* this Software only as provided in the license agreement accompanying the *
|
||||
* software package from which you obtained this Software ("EULA"). *
|
||||
* *
|
||||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
|
||||
* non-transferable license to copy, modify, and compile the *
|
||||
* Software source code solely for use in connection with Cypress's *
|
||||
* integrated circuit products. Any reproduction, modification, translation, *
|
||||
* compilation, or representation of this Software except as specified *
|
||||
* above is prohibited without the express written permission of Cypress. *
|
||||
* *
|
||||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
|
||||
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
|
||||
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. Cypress reserves the right to make *
|
||||
* changes to the Software without notice. Cypress does not assume any *
|
||||
* liability arising out of the application or use of the Software or any *
|
||||
* product or circuit described in the Software. Cypress does not *
|
||||
* authorize its products for use in any products where a malfunction or *
|
||||
* failure of the Cypress product may reasonably be expected to result in *
|
||||
* significant property damage, injury or death ("High Risk Product"). By *
|
||||
* including Cypress's product in a High Risk Product, the manufacturer *
|
||||
* of such system or application assumes all risk of such use and in doing *
|
||||
* so agrees to indemnify Cypress against all liability. *
|
||||
*******************************************************************************/
|
||||
/************************************************************************/
|
||||
/** \file usbdevicehw.h
|
||||
**
|
||||
** - See README.TXT for project description
|
||||
** - pre release for a simple universal usb function library
|
||||
**
|
||||
** History:
|
||||
** - 2010-03-30 1.0 MSc First version (works with 16FX,FR80)
|
||||
** - 2011-03-30 1.1 MSc New HW description style
|
||||
** - 2016-06-23 1.2 MSc Updated for use with MCU Templates >= v2.0
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __USBDEVICEHW_H__
|
||||
#define __USBDEVICEHW_H__
|
||||
|
||||
#define DEVICE0VBUS_DISABLEISR
|
||||
#define DEVICE0VBUS_ENABLEISR
|
||||
#define DEVICE0VBUS_ISRISSET 0
|
||||
#define DEVICE0VBUS_CLEARISRFLAG
|
||||
#define DEVICE0VBUS_SETLOWDETECT
|
||||
#define DEVICE0VBUS_SETHIGHDETECT
|
||||
#define DEVICE0VBUS_HIGHDETECT Gpio1pin_Get( GPIO1PIN_P60 )
|
||||
#define DEVICE0VBUS_INIT Gpio1pin_InitIn( GPIO1PIN_P60, Gpio1pin_InitPullup( 0u ) )
|
||||
#define DEVICE0VBUS_DEINIT
|
||||
#define DEVICE0VBUS_ENABLED 1
|
||||
|
||||
#define DEVICE0HCONX_INIT
|
||||
#define DEVICE0HCONX_SET
|
||||
#define DEVICE0HCONX_CLEAR
|
||||
#define DEVICE0HCONX_ENABLED 1
|
||||
|
||||
#define DEVICE1VBUS_DISABLEISR
|
||||
#define DEVICE1VBUS_ENABLEISR
|
||||
#define DEVICE1VBUS_ISRISSET 0
|
||||
#define DEVICE1VBUS_CLEARISRFLAG
|
||||
#define DEVICE1VBUS_SETLOWDETECT
|
||||
#define DEVICE1VBUS_SETHIGHDETECT
|
||||
#define DEVICE1VBUS_HIGHDETECT (0)
|
||||
#define DEVICE1VBUS_INIT
|
||||
#define DEVICE1VBUS_DEINIT
|
||||
#define DEVICE1VBUS_ENABLED 0
|
||||
|
||||
#define DEVICE1HCONX_INIT
|
||||
#define DEVICE1HCONX_SET
|
||||
#define DEVICE1HCONX_CLEAR
|
||||
#define DEVICE1HCONX_ENABLED 0
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
|
||||
* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
|
||||
* *
|
||||
* This software, including source code, documentation and related *
|
||||
* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
|
||||
* one of its subsidiaries ("Cypress") and is protected by and subject to *
|
||||
* worldwide patent protection (United States and foreign), United States *
|
||||
* copyright laws and international treaty provisions. Therefore, you may use *
|
||||
* this Software only as provided in the license agreement accompanying the *
|
||||
* software package from which you obtained this Software ("EULA"). *
|
||||
* *
|
||||
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
|
||||
* non-transferable license to copy, modify, and compile the *
|
||||
* Software source code solely for use in connection with Cypress's *
|
||||
* integrated circuit products. Any reproduction, modification, translation, *
|
||||
* compilation, or representation of this Software except as specified *
|
||||
* above is prohibited without the express written permission of Cypress. *
|
||||
* *
|
||||
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
|
||||
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
|
||||
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. Cypress reserves the right to make *
|
||||
* changes to the Software without notice. Cypress does not assume any *
|
||||
* liability arising out of the application or use of the Software or any *
|
||||
* product or circuit described in the Software. Cypress does not *
|
||||
* authorize its products for use in any products where a malfunction or *
|
||||
* failure of the Cypress product may reasonably be expected to result in *
|
||||
* significant property damage, injury or death ("High Risk Product"). By *
|
||||
* including Cypress's product in a High Risk Product, the manufacturer *
|
||||
* of such system or application assumes all risk of such use and in doing *
|
||||
* so agrees to indemnify Cypress against all liability. *
|
||||
*******************************************************************************/
|
||||
/************************************************************************/
|
||||
/** \file UsbHostHW.h
|
||||
**
|
||||
** USB hardware specific settings
|
||||
**
|
||||
** History:
|
||||
** - 2010-10-14 1.0 MSc First version (works with 16FX,FR80)
|
||||
** - 2011-03-30 1.1 MSc Compatible with FSEU Host drivers 2011-03-30
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __USBHOSTHW_H__
|
||||
#define __USBHOSTHW_H__
|
||||
|
||||
#define HOST0VBUS_DEINIT
|
||||
#define HOST0VBUS_INIT
|
||||
#define HOST0VBUS_SET
|
||||
#define HOST0VBUS_CLEAR
|
||||
#define HOST0VBUS_GET
|
||||
#define HOST0VBUS_ENABLED 0
|
||||
|
||||
#define HOST0OTGPULLDOWN_DEINIT
|
||||
#define HOST0OTGPULLDOWN_INIT
|
||||
#define HOST0OTGPULLDOWN_SET
|
||||
#define HOST0OTGPULLDOWN_CLEAR
|
||||
#define HOST0OTGPULLDOWN_GET 1
|
||||
#define HOST0OTGPULLDOWN_ENABLED 0
|
||||
|
||||
#define HOST0OVERCURRENT_DISABLEISR
|
||||
#define HOST0OVERCURRENT_ENABLEISR
|
||||
#define HOST0OVERCURRENT_CLEARISRFLAG
|
||||
#define HOST0OVERCURRENT_ISRISSET 0
|
||||
#define HOST0OVERCURRENT_SETLOWDETECT
|
||||
#define HOST0OVERCURRENT_SETHIGHDETECT
|
||||
#define HOST0OVERCURRENT_HIGHDETECT 0
|
||||
#define HOST0OVERCURRENT_INIT
|
||||
#define HOST0OVERCURRENT_DEINIT
|
||||
#define HOST0OVERCURRENT_ENABLED 0
|
||||
|
||||
|
||||
#define HOST1VBUS_DEINIT
|
||||
#define HOST1VBUS_INIT
|
||||
#define HOST1VBUS_SET
|
||||
#define HOST1VBUS_CLEAR
|
||||
#define HOST1VBUS_GET 0
|
||||
#define HOST1VBUS_ENABLED 0
|
||||
|
||||
#define HOST1OTGPULLDOWN_DEINIT
|
||||
#define HOST1OTGPULLDOWN_INIT
|
||||
#define HOST1OTGPULLDOWN_SET
|
||||
#define HOST1OTGPULLDOWN_CLEAR
|
||||
#define HOST1OTGPULLDOWN_GET 1
|
||||
#define HOST1OTGPULLDOWN_ENABLED 0
|
||||
|
||||
#define HOST1OVERCURRENT_DISABLEISR
|
||||
#define HOST1OVERCURRENT_ENABLEISR
|
||||
#define HOST1OVERCURRENT_CLEARISRFLAG
|
||||
#define HOST1OVERCURRENT_ISRISSET 0
|
||||
#define HOST1OVERCURRENT_SETLOWDETECT
|
||||
#define HOST1OVERCURRENT_SETHIGHDETECT
|
||||
#define HOST1OVERCURRENT_HIGHDETECT 0
|
||||
#define HOST1OVERCURRENT_INIT
|
||||
#define HOST1OVERCURRENT_DEINIT
|
||||
#define HOST0OVERCURRENT_ENABLED 0
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue