-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
52,893 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
120 changes: 120 additions & 0 deletions
120
Firmware/EFM8/sdk/Device/EFM8UB2/bsp/efm8_memory_lcd/spi.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/**************************************************************************//** | ||
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. | ||
* | ||
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt | ||
*****************************************************************************/ | ||
///////////////////////////////////////////////////////////////////////////// | ||
// Spi.c | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
// SPI FIFO Format | ||
// --------------- | ||
// | ||
// All SPI transfers are pushed to the TX FIFO with the transfer size in | ||
// bytes followed by the data to transmit. | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Includes | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "bsp.h" | ||
#include "spi.h" | ||
#include "spi_0.h" | ||
#include <string.h> | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Globals | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); | ||
|
||
static volatile uint8_t TransferState = ST_IDLE; | ||
static volatile uint8_t TransferSize = 0; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Functions | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) | ||
{ | ||
uint8_t sfrPageSave; | ||
uint8_t i; | ||
|
||
// Wait for previous transfer to complete | ||
while (TransferState != ST_IDLE); | ||
|
||
// Start new transfer | ||
TransferState = ST_CS_SETUP; | ||
TransferSize = size; | ||
|
||
for (i = 0; i < size; i++) | ||
{ | ||
TxBuffer[i] = buffer[i]; | ||
} | ||
|
||
sfrPageSave = SFRPAGE; | ||
SFRPAGE = LEGACY_PAGE; | ||
|
||
// CS setup time | ||
// Timer 2 overflows at end of setup time | ||
TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); | ||
BSP_DISP_CS = SPI_CS_ASSERT_LVL; | ||
TMR2CN0 |= TMR2CN0_TR2__BMASK; | ||
|
||
SFRPAGE = sfrPageSave; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Interrupt Service Handlers | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
void SPI0_transferCompleteCb(void) | ||
{ | ||
uint8_t sfrPageSave; | ||
|
||
// CS hold time | ||
TransferState = ST_CS_HOLD; | ||
|
||
sfrPageSave = SFRPAGE; | ||
SFRPAGE = LEGACY_PAGE; | ||
|
||
// CS hold time | ||
// Timer 2 overflows at end of hold time | ||
TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); | ||
TMR2CN0 |= TMR2CN0_TR2__BMASK; | ||
|
||
SFRPAGE = sfrPageSave; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// TIMER2_ISR | ||
//----------------------------------------------------------------------------- | ||
// | ||
// TIMER2 ISR Content goes here. Remember to clear flag bits: | ||
// TMR2CN::TF2H (Timer # High Byte Overflow Flag) | ||
// TMR2CN::TF2L (Timer # Low Byte Overflow Flag) | ||
// | ||
//----------------------------------------------------------------------------- | ||
SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) | ||
{ | ||
TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; | ||
|
||
// Stop timer | ||
TMR2CN0 &= ~TMR2CN0_TR2__BMASK; | ||
|
||
// CS setup complete | ||
if (TransferState == ST_CS_SETUP) | ||
{ | ||
TransferState = ST_TX; | ||
SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); | ||
} | ||
// CS hold complete | ||
else if (TransferState == ST_CS_HOLD) | ||
{ | ||
// Deassert CS | ||
BSP_DISP_CS = SPI_CS_DEASSERT_LVL; | ||
|
||
// Transfer complete | ||
TransferState = ST_IDLE; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
Firmware/EFM8/sdk/Device/EFM8UB2/bsp/efm8_memory_lcd/tick.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/**************************************************************************//** | ||
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. | ||
* | ||
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt | ||
*****************************************************************************/ | ||
///////////////////////////////////////////////////////////////////////////// | ||
// Tick.c | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Includes | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "bsp.h" | ||
#include "tick.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Globals | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
static volatile uint16_t Ticks = 0; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Functions | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
//--------------------------------------------------------------------------- | ||
// GetTickCount | ||
//--------------------------------------------------------------------------- | ||
// | ||
// Description - Return the system up time in milliseconds | ||
// | ||
// return - Number of milliseconds since system start. | ||
// | ||
uint16_t GetTickCount() | ||
{ | ||
uint16_t ticks; | ||
|
||
// Disable Timer 3 interrupts | ||
EIE1 &= ~EIE1_ET3__BMASK; | ||
|
||
ticks = Ticks; | ||
|
||
// Enable Timer 3 interrupts | ||
EIE1 |= EIE1_ET3__BMASK; | ||
|
||
return ticks; | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
// Wait | ||
//--------------------------------------------------------------------------- | ||
// | ||
// Description - Wait the specified number of milliseconds | ||
// | ||
// ms - The number of milliseconds to wait | ||
// | ||
void Wait(uint16_t ms) | ||
{ | ||
uint16_t ticks = GetTickCount(); | ||
|
||
while ((GetTickCount() - ticks) < ms); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// TIMER3_ISR | ||
//----------------------------------------------------------------------------- | ||
// | ||
// TIMER3 ISR Content goes here. Remember to clear flag bits: | ||
// TMR3CN::TF3H (Timer # High Byte Overflow Flag) | ||
// TMR3CN::TF3L (Timer # Low Byte Overflow Flag) | ||
// | ||
//----------------------------------------------------------------------------- | ||
SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) | ||
{ | ||
// Overflows every 1 ms | ||
TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; | ||
|
||
Ticks++; | ||
} |
Oops, something went wrong.