(Unfortunately) there are changes to MIOS32 files necessary (albeit minor changes) but allow for compatibility by using mios32_config.h switches:
The modified mios32 files are attached below. I’ve highlighted the changes in this post for explanation. They consist of dout driver modification (mios32_srio.c,.h) and array access (mios32_dout.c,h). The application specific layer above this e.g void SetLed(u32 LedIndex, u32 Level) is written by you!
#define MIOS32_USE_PAGED_DOUT
#define DOUT_NUM_BUFPAGES 4
This means that 4 pages are used e.g an LED may be off, or have a brightness of 1,2,3 or 4.
In mios_srio.h (file is attahced) the array is declared:
#ifdef MIOS32_USE_PAGED_DOUT
extern volatile u8 mios32_srio_dout_bufpages[DOUT_NUM_BUFPAGES][MIOS32_SRIO_NUM_SR];
#endif
mios32_srio.c (file is attached with this post ) for reference I’ll highlight the changes here:
Define two dimensional array:
#ifdef MIOS32_USE_PAGED_DOUT
volatile u8 mios32_srio_dout_bufpages[DOUT_NUM_BUFPAGES][MIOS32_SRIO_NUM_SR];
#endif
…
// inside s32 MIOS32_SRIO_Init(u32 mode) array is initialised:
for(i=0; i<MIOS32_SRIO_NUM_SR; ++i) {
#ifdef MIOS32_USE_PAGED_DOUT
for(j=0;j<DOUT_NUM_BUFPAGES;++j) mios32_srio_dout_bufpages[j]_ =0; _
#endif
mios32_srio_dout = 0x00; // passive state (LEDs off)
mios32_srio_din = 0xff; // passive state (Buttons depressed)
mios32_srio_din_buffer = 0xff; // passive state (Buttons depressed)
mios32_srio_din_changed _ = 0; // no change _
}
Now the guts of it all in s32 MIOS32_SRIO_ScanStart(void *_notify_hook) where the next page is indexed, and it’s address loaded into the DMA process:
current_bufpage=(++current_bufpage)%DOUT_NUM_BUFPAGES; //roll through page range
u8 *dout_address = (u8 *)&mios32_srio_dout_bufpages[current_bufpage][0]; //set pointer
// start DMA transfer
MIOS32_SPI_TransferBlock(MIOS32_SRIO_SPI,
dout_address, (u8 *)&mios32_srio_din_buffer[0],
MIOS32_SRIO_NUM_SR,
MIOS32_SRIO_DMA_Callback);
Now in mios32_dout.h the paged array access functions are dedclared (for some reason I included NR (not bit reversed) versions of these functions as well):
extern s32 MIOS32_DOUT_SRSet_Paged(u32 pg, u32 sr, u8 value);
extern s32 MIOS32_DOUT_SRGet_Paged(u32 pg, u32 sr);
extern s32 MIOS32_DOUT_SRSet_Paged_NR(u32 pg, u32 sr, u8 value);
extern s32 MIOS32_DOUT_SRGet_Paged_NR(u32 pg, u32 sr);
The paged array access functions as they appear in mios32_dout.c:
#ifdef MIOS32_USE_PAGED_DOUT
s32 MIOS32_DOUT_SRGet_Paged(u32 pg, u32 sr)
{
// check if SR available
if( sr >= MIOS32_SRIO_NUM_SR )
return -1;
return mios32_dout_reverse_tab[mios32_srio_dout_bufpages[pg][MIOS32_SRIO_NUM_SR - sr - 1]];
}
s32 MIOS32_DOUT_SRSet_Paged(u32 pg, u32 sr, u8 value)
{
// check if SR available
if( sr >= MIOS32_SRIO_NUM_SR )
return -1;
mios32_srio_dout_bufpages[pg][MIOS32_SRIO_NUM_SR - sr - 1]=mios32_dout_reverse_tab[value];
return 0;
}
// NON REVERSED (range check on SR also removed)
s32 MIOS32_DOUT_SRGet_Paged_NR(u32 pg, u32 sr)
{
return mios32_srio_dout_bufpages[pg][MIOS32_SRIO_NUM_SR - sr - 1];
}
s32 MIOS32_DOUT_SRSet_Paged_NR(u32 pg, u32 sr, u8 value)
{
mios32_srio_dout_bufpages[pg][MIOS32_SRIO_NUM_SR - sr - 1]=value;
return 0;
}
#endif
So now the more application specific part you have to write for yourself for example:
void SetLed(u32 LedIndex, u32 Level)
would copy a bit pattern into the pages at LedIndex according to Level.
These routines can be used to drive matrix arrays by having a column/row mask on each page.
This can be combined with PWM/PDM values as well for e.g RGB full colour array!
Please note these modified files need to replace the existing ones. The mios32_config.h config switches mean that other applications will compile and run as before. Take care that you merge any changes (although unlikely) to these mios32 files. Perhaps Thorsten can suggest a better way of managing this?
[mios32_srio.h](< base_url >/applications/core/interface/file/attachment.php?id=9996)
[mios32_srio.c](< base_url >/applications/core/interface/file/attachment.php?id=9995)
[mios32_dout.h](< base_url >/applications/core/interface/file/attachment.php?id=9997)
[mios32_dout.c](< base_url >/applications/core/interface/file/attachment.php?id=9998)