Ok - I think I've found the error - if not the fix....
As I understand it : If a second component attempts to use an 'already in use' SPI channel then calls to use the second SPI channel 'redirect' to the first... (in ESP_CAL_SPI.c)
For example
Code: Select all
#define MX_SPI_RED1 CAL_APPEND(FC_CAL_SPI_Master_Init_, MX_SPI_CHANNEL_IN_USE)
CALFUNCTION(MX_UINT8, FC_CAL_SPI_Master_Init_, (void)) { return MX_SPI_RED1(); }
Should create a 'redirect' function for Init.
Something isn't quite right with this. I modified the Master_Byte redirect code slightly and this fixes the sample above:
Code: Select all
//#define MX_SPI_RED3 CAL_APPEND(FC_CAL_SPI_Master_Byte_, MX_SPI_CHANNEL_IN_USE)
#define MX_SPI_RED3 FC_CAL_SPI_Master_Byte_1
CALFUNCTION(MX_UINT8, FC_CAL_SPI_Master_Byte_, (MX_UINT8 DataOut)) { return MX_SPI_RED3(DataOut); }
Note - I've simply hard-coded channel 2 to redirect to channel 1 (note the nomenclature is slightly confusing - so this is redirecting Cal_SPI2 to use channel 1 which is also in use by Cal_SPI1....
The sample code then works
However - there is more work to do (all the other functions - yes) - and to 'generalise' the code - MX_SPI_CHANNEL_IN_USE should equal 1 but doesn't for some reason... I'd guess it must equal 2 and this creates a recursive crash - otherwise some function not found errors would result?
Also - the esp32 doesn't like a channel being initialised multiple times - so if multiple components use the same channel then the 'initialisation' needs to be a bit smarter. (This issue can be sidestepped with the display and touch sensor - the user can omit the call to the Touch sensor initialisation - which only does CAL_SPI_Init - but again not a general fix)
Martin