changes to make firmware interop on all hw models

This commit is contained in:
Conor Patrick
2019-05-09 16:01:07 -04:00
parent 4ac61f7f18
commit 84740f3d6a
9 changed files with 38 additions and 19 deletions

View File

@ -99,9 +99,8 @@ typedef enum {
// 2: fastest clock rate. Generally for USB interface. // 2: fastest clock rate. Generally for USB interface.
void device_set_clock_rate(DEVICE_CLOCK_RATE param); void device_set_clock_rate(DEVICE_CLOCK_RATE param);
// Returns 1 if operating in NFC mode. // Returns NFC_IS_NA (0), NFC_IS_ACTIVE (1), or NFC_IS_AVAILABLE (2)
// 0 otherwise. int device_is_nfc();
bool device_is_nfc();
void device_init_button(); void device_init_button();

View File

@ -270,7 +270,7 @@ void ams_print_int1(uint8_t int0)
#endif #endif
} }
void ams_init() int ams_init()
{ {
LL_GPIO_SetPinMode(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN,LL_GPIO_MODE_OUTPUT); LL_GPIO_SetPinMode(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN,LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN); LL_GPIO_SetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN);
@ -283,6 +283,13 @@ void ams_init()
// delay(10); // delay(10);
SELECT(); SELECT();
delay(1); delay(1);
uint8_t productType = ams_read_reg(AMS_REG_PRODUCT_TYPE);
if (productType == 0x14)
{
return 1;
}
return 0;
} }
void ams_configure() void ams_configure()

View File

@ -39,7 +39,7 @@ typedef union
#define SELECT() LL_GPIO_ResetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN) #define SELECT() LL_GPIO_ResetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN)
#define UNSELECT() LL_GPIO_SetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN) #define UNSELECT() LL_GPIO_SetOutputPin(SOLO_AMS_CS_PORT,SOLO_AMS_CS_PIN)
void ams_init(); int ams_init();
void ams_configure(); void ams_configure();
void ams_read_buffer(uint8_t * data, int len); void ams_read_buffer(uint8_t * data, int len);

View File

@ -72,6 +72,6 @@ void hw_init(int lf);
#define SOLO_AMS_IRQ_PIN LL_GPIO_PIN_15 #define SOLO_AMS_IRQ_PIN LL_GPIO_PIN_15
#define SKIP_BUTTON_CHECK_WITH_DELAY 0 #define SKIP_BUTTON_CHECK_WITH_DELAY 0
#define SKIP_BUTTON_CHECK_FAST 1 #define SKIP_BUTTON_CHECK_FAST 0
#endif #endif

View File

@ -41,7 +41,7 @@ uint32_t __90_ms = 0;
uint32_t __device_status = 0; uint32_t __device_status = 0;
uint32_t __last_update = 0; uint32_t __last_update = 0;
extern PCD_HandleTypeDef hpcd; extern PCD_HandleTypeDef hpcd;
static bool haveNFC = 0; static int _NFC_status = 0;
static bool isLowFreq = 0; static bool isLowFreq = 0;
// #define IS_BUTTON_PRESSED() (0 == (LL_GPIO_ReadInputPort(SOLO_BUTTON_PORT) & SOLO_BUTTON_PIN)) // #define IS_BUTTON_PRESSED() (0 == (LL_GPIO_ReadInputPort(SOLO_BUTTON_PORT) & SOLO_BUTTON_PIN))
@ -138,7 +138,12 @@ void device_init(int argc, char *argv[])
hw_init(LOW_FREQUENCY); hw_init(LOW_FREQUENCY);
if (haveNFC) if (! tsc_sensor_exists())
{
_NFC_status = nfc_init();
}
if (_NFC_status == NFC_IS_ACTIVE)
{ {
printf1(TAG_NFC, "Have NFC\r\n"); printf1(TAG_NFC, "Have NFC\r\n");
isLowFreq = 1; isLowFreq = 1;
@ -165,9 +170,9 @@ void device_init(int argc, char *argv[])
} }
bool device_is_nfc() int device_is_nfc()
{ {
return haveNFC; return _NFC_status;
} }
void wait_for_usb_tether() void wait_for_usb_tether()

View File

@ -31,6 +31,7 @@
#include "usbd_cdc_if.h" #include "usbd_cdc_if.h"
#include "device.h" #include "device.h"
#include "init.h" #include "init.h"
#include "sense.h"
#include APP_CONFIG #include APP_CONFIG
// KHz // KHz
@ -94,8 +95,6 @@ void hw_init(int lowfreq)
SystemClock_Config(); SystemClock_Config();
} }
if (!lowfreq) if (!lowfreq)
{ {
init_pwm(); init_pwm();
@ -108,7 +107,8 @@ void hw_init(int lowfreq)
#endif #endif
init_rng(); init_rng();
//init_spi();
init_spi();
} }

View File

@ -55,11 +55,12 @@ void nfc_state_init()
NFC_STATE.block_num = 1; NFC_STATE.block_num = 1;
} }
bool nfc_init() int nfc_init()
{ {
uint32_t t1; uint32_t t1;
int init;
nfc_state_init(); nfc_state_init();
ams_init(); init = ams_init();
// Detect if we are powered by NFC field by listening for a message for // Detect if we are powered by NFC field by listening for a message for
// first 10 ms. // first 10 ms.
@ -67,13 +68,14 @@ bool nfc_init()
while ((millis() - t1) < 10) while ((millis() - t1) < 10)
{ {
if (nfc_loop() > 0) if (nfc_loop() > 0)
return 1; return NFC_IS_ACTIVE;
} }
// Under USB power. Configure AMS chip. // Under USB power. Configure AMS chip.
ams_configure(); ams_configure();
return 0; return NFC_IS_AVAILABLE;
return NFC_IS_NA;
} }
void process_int0(uint8_t int0) void process_int0(uint8_t int0)

View File

@ -8,7 +8,11 @@
// Return number of bytes read if any. // Return number of bytes read if any.
int nfc_loop(); int nfc_loop();
bool nfc_init(); int nfc_init();
#define NFC_IS_NA 0
#define NFC_IS_ACTIVE 1
#define NFC_IS_AVAILABLE 2
typedef struct typedef struct
{ {

View File

@ -119,7 +119,9 @@ uint32_t tsc_read_button(uint32_t index)
int tsc_sensor_exists() int tsc_sensor_exists()
{ {
int does; static uint8_t does = 0;
if (does) return 1;
LL_GPIO_SetPinMode(GPIOB, (1 << 1), LL_GPIO_MODE_INPUT); LL_GPIO_SetPinMode(GPIOB, (1 << 1), LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(GPIOB, (1 << 1), LL_GPIO_PULL_UP); LL_GPIO_SetPinPull(GPIOB, (1 << 1), LL_GPIO_PULL_UP);