├── examples └── blink │ ├── boards │ └── default │ │ └── config.mk │ ├── src │ └── main.c │ └── Makefile ├── efm8 ├── mcu │ ├── EFM8BB2 │ │ ├── peripheral_driver │ │ │ ├── src │ │ │ │ ├── si8_fifo.c │ │ │ │ ├── wdt_0.c │ │ │ │ └── pwr.c │ │ │ └── inc │ │ │ │ └── si8_fifo.h │ │ ├── bsp │ │ │ └── efm8_memory_lcd │ │ │ │ ├── tick.c │ │ │ │ └── spi.c │ │ └── inc │ │ │ └── SI_EFM8BB2_Devices.h │ ├── EFM8UB1 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ ├── USBXpress │ │ │ └── efm8ub1_usbxpress.lib │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ └── pwr.c │ │ ├── inc │ │ │ └── SI_EFM8UB1_Devices.h │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ ├── tick.c │ │ │ └── spi.c │ ├── EFM8UB2 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ ├── USBXpress │ │ │ └── efm8ub2_usbxpress.lib │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ └── pwr.c │ │ ├── inc │ │ │ └── SI_EFM8UB2_Devices.h │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ ├── tick.c │ │ │ └── spi.c │ ├── EFM8UB3 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ ├── USBXpress │ │ │ └── efm8ub3_usbxpress.lib │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ └── pwr.c │ │ └── inc │ │ │ └── SI_EFM8UB3_Devices.h │ ├── C8051F320 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ └── USBXpress │ │ │ └── c8051f320_usbxpress.lib │ ├── C8051F326 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ └── USBXpress │ │ │ └── c8051f326_usbxpress.lib │ ├── C8051F340 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ └── USBXpress │ │ │ └── c8051f340_usbxpress.lib │ ├── C8051F380 │ │ ├── VCPXpress │ │ │ └── VCPXpress.lib │ │ ├── USBXpress │ │ │ └── c8051f380_usbxpress.lib │ │ └── meta-inf │ │ │ ├── plugins.info │ │ │ ├── layout.properties │ │ │ ├── callbacks.info │ │ │ └── appbuilder.properties │ ├── C8051T321 │ │ └── Log.txt │ ├── C8051F970 │ │ └── efm8_capsense │ │ │ ├── device_layer │ │ │ ├── low_power_config.h │ │ │ ├── hardware_routines.h │ │ │ └── hardware_config.c │ │ │ └── serial_interface │ │ │ ├── sensor_descriptors.c │ │ │ ├── comm_routines.h │ │ │ └── profiler_interface.h │ ├── C8051F990 │ │ └── efm8_capsense │ │ │ ├── device_layer │ │ │ ├── low_power_config.h │ │ │ ├── hardware_routines.h │ │ │ └── hardware_config.c │ │ │ └── serial_interface │ │ │ ├── sensor_descriptors.c │ │ │ ├── comm_routines.h │ │ │ └── profiler_interface.h │ ├── EFM8SB1 │ │ ├── efm8_capsense │ │ │ ├── serial_interface │ │ │ │ ├── sensor_descriptors.c │ │ │ │ ├── comm_routines.h │ │ │ │ └── profiler_interface.h │ │ │ └── device_layer │ │ │ │ ├── low_power_config.h │ │ │ │ ├── hardware_routines.h │ │ │ │ └── hardware_config.c │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ └── wdt_0.c │ │ ├── bsp │ │ │ └── efm8_memory_lcd │ │ │ │ ├── tick.c │ │ │ │ └── spi.c │ │ └── inc │ │ │ └── SI_EFM8SB1_Devices.h │ ├── EFM8BB1 │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ ├── pwr.c │ │ │ │ └── adc_0.c │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ ├── tick.c │ │ │ └── spi.c │ ├── EFM8BB3 │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ ├── dac_0.c │ │ │ │ ├── dac_1.c │ │ │ │ ├── dac_2.c │ │ │ │ ├── dac_3.c │ │ │ │ ├── cl_0_isr.c │ │ │ │ ├── clu_0.c │ │ │ │ ├── clu_1.c │ │ │ │ ├── clu_2.c │ │ │ │ └── clu_3.c │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ └── source │ │ │ ├── tick.c │ │ │ └── spi.c │ ├── EFM8LB1 │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ ├── wdt_0.c │ │ │ │ ├── dac_0.c │ │ │ │ ├── dac_1.c │ │ │ │ ├── dac_2.c │ │ │ │ ├── dac_3.c │ │ │ │ ├── cl_0_isr.c │ │ │ │ ├── clu_0.c │ │ │ │ ├── clu_1.c │ │ │ │ ├── clu_2.c │ │ │ │ └── clu_3.c │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ ├── tick.c │ │ │ └── spi.c │ ├── EFM8SB2 │ │ ├── peripheral_driver │ │ │ └── src │ │ │ │ └── wdt_0.c │ │ ├── inc │ │ │ └── SI_EFM8SB2_Devices.h │ │ └── bsp │ │ │ └── efm8_memory_lcd │ │ │ ├── tick.c │ │ │ └── spi.c │ └── EFM8UB4 │ │ └── inc │ │ └── SI_EFM8UB4_Devices.h ├── efm8_util │ ├── delay.h │ ├── watchdog.h │ └── delay.c ├── efm8_program.mk ├── efm8_sfr.h ├── scripts │ └── hex-size.sh ├── sdcc.mk ├── si8051Base │ └── endian.h ├── boards.mk └── efm8.mk └── README.md /examples/blink/boards/default/config.mk: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/peripheral_driver/src/si8_fifo.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB1/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB2/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB3/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB3/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F320/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F320/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F326/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F326/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F340/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F340/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F380/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/USBXpress/efm8ub1_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB1/USBXpress/efm8ub1_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/USBXpress/efm8ub2_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB2/USBXpress/efm8ub2_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB3/USBXpress/efm8ub3_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/EFM8UB3/USBXpress/efm8ub3_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F320/USBXpress/c8051f320_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F320/USBXpress/c8051f320_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F326/USBXpress/c8051f326_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F326/USBXpress/c8051f326_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F340/USBXpress/c8051f340_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F340/USBXpress/c8051f340_usbxpress.lib -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/USBXpress/c8051f380_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/efm8_sdcc/HEAD/efm8/mcu/C8051F380/USBXpress/c8051f380_usbxpress.lib -------------------------------------------------------------------------------- /efm8/efm8_util/delay.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | void efm8_delay_us(uint16_t us); 7 | void efm8_delay_ms(uint16_t ms); 8 | -------------------------------------------------------------------------------- /efm8/efm8_util/watchdog.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "efm8_sfr.h" 5 | 6 | // Disable the watchdog timer 7 | static inline 8 | void efm8_watchdog_disable(void) { 9 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 10 | } 11 | -------------------------------------------------------------------------------- /efm8/mcu/C8051T321/Log.txt: -------------------------------------------------------------------------------- 1 | Copy and paste F340 original USB files into T620. Image file no modification yet. 2 | 7/14 4:51PM 3 | 4 | change all text "F340" to "T620", leave the addresses and values (especially for SI_C8051T620_Register_Enums.h) unchanged. 5 | 7/14 5:07PM 6 | 7 | Change name from T620 to T321. 8 | 7/21 10:00AM -------------------------------------------------------------------------------- /efm8/efm8_program.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | .PHONY: 5 | program-list: $(TARGET_HEX) 6 | $(INSPECT_8051) -slist 7 | 8 | .PHONY: 9 | program-efm8: $(TARGET_HEX) 10 | $(FLASH_EFM8) -sn $(SERIAL_NUM) -upload $(TARGET).hex -erasemode page 11 | 12 | .PHONY: 13 | program-c8051: $(TARGET_HEX) 14 | $(FLASH_8051) -sn $(SERIAL_NUM) -upload $(TARGET).hex -erasemode page 15 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/meta-inf/plugins.info: -------------------------------------------------------------------------------- 1 | This file can list directories where to load plugins from or 2 | # declare virtual plugins. 3 | # Any line that says: pluginDirectory=RELATIVE/PATH/ 4 | # will cause appbuilder to read in that directory for plugin subdirectories. 5 | # 6 | # Virtual plugins are declared with sections: 7 | # plugin(xxx) { 8 | # BLOCK IDENTICAL TO plugin.properties 9 | # } 10 | 11 | 12 | #pluginDirectory=../plugins/ 13 | 14 | 15 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/meta-inf/layout.properties: -------------------------------------------------------------------------------- 1 | tabs=general, hal, plugins, callbacks, other 2 | 3 | general.name=General 4 | general.icon=EMBER 5 | general.0=application 6 | 7 | hal.name=HAL 8 | hal.icon=HAL 9 | hal.0=setup.boardHeader 10 | 11 | plugins.name=Plugins 12 | plugins.icon=PLUGIN 13 | plugins.0=plugins 14 | 15 | callbacks.name=Callbacks 16 | callbacks.icon=CALLBACK 17 | callbacks.0=setup.callbackConfiguration 18 | 19 | other.name=Other 20 | other.icon=OTHER 21 | other.0=setup.macros 22 | other.1=setup.eventConfiguration 23 | other.2=setup.additionalFiles 24 | other.3=setup.template 25 | 26 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/meta-inf/callbacks.info: -------------------------------------------------------------------------------- 1 | #include PLATFORM_HEADER 2 | #include CONFIGURATION_HEADER 3 | #include "stack/include/ember.h" 4 | 5 | void main(void) 6 | { 7 | emberInit(); 8 | emberNetworkInit(); 9 | while (TRUE) { 10 | emberTick(); 11 | } 12 | } 13 | 14 | void emberIncomingMessageHandler(EmberIncomingMessage *message) 15 | { 16 | UNUSED_VAR(message); 17 | } 18 | 19 | void emberMessageSentHandler(EmberStatus status, EmberOutgoingMessage *message) 20 | { 21 | UNUSED_VAR(status); 22 | UNUSED_VAR(message); 23 | } 24 | 25 | void emberStackStatusHandler(EmberStatus status) 26 | { 27 | UNUSED_VAR(status); 28 | } 29 | 30 | void emberPacketTraceHandler(EmberMessageTrace *trace) 31 | { 32 | UNUSED_VAR(trace); 33 | } -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/device_layer/low_power_config.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _LOW_POWER_CONFIG_H 8 | #define _LOW_POWER_CONFIG_H 9 | 10 | 11 | // Functions which must be defined with implementation-specific 12 | // responsibilities. These are called by LowPowerRoutines.c 13 | void CSLIB_configureSensorForSleepModeCB(void); 14 | void CSLIB_configureTimerForSleepModeCB(void); 15 | void CSLIB_configureTimerForActiveModeCB(void); 16 | void CSLIB_enterLowPowerStateCB(void); 17 | void CSLIB_checkTimerCB(void); 18 | extern xdata uint8_t timerTick; 19 | 20 | 21 | #endif -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/device_layer/low_power_config.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _LOW_POWER_CONFIG_H 8 | #define _LOW_POWER_CONFIG_H 9 | 10 | 11 | // Functions which must be defined with implementation-specific 12 | // responsibilities. These are called by LowPowerRoutines.c 13 | void CSLIB_configureSensorForSleepModeCB(void); 14 | void CSLIB_configureTimerForSleepModeCB(void); 15 | void CSLIB_configureTimerForActiveModeCB(void); 16 | void CSLIB_enterLowPowerStateCB(void); 17 | void CSLIB_checkTimerCB(void); 18 | extern xdata uint8_t timerTick; 19 | 20 | 21 | #endif -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/serial_interface/sensor_descriptors.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include 9 | #include 10 | #include "cslib_sensor_descriptors.h" 11 | 12 | code char* sensorDescriptors[DEF_NUM_SENSORS] = 13 | { 14 | SENSOR_DESCRIPTOR_LIST 15 | }; 16 | 17 | void outputsensorDescriptors(void) 18 | { 19 | uint8_t index; 20 | printf("*SENSOR_DESCRIPTORS "); 21 | for(index = 0; index < DEF_NUM_SENSORS; index++) 22 | { 23 | printf("%s | ",sensorDescriptors[index]); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/serial_interface/sensor_descriptors.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include 9 | #include 10 | #include "cslib_sensor_descriptors.h" 11 | 12 | code char* sensorDescriptors[DEF_NUM_SENSORS] = 13 | { 14 | SENSOR_DESCRIPTOR_LIST 15 | }; 16 | 17 | void outputsensorDescriptors(void) 18 | { 19 | uint8_t index; 20 | printf("*SENSOR_DESCRIPTORS "); 21 | for(index = 0; index < DEF_NUM_SENSORS; index++) 22 | { 23 | printf("%s | ",sensorDescriptors[index]); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/serial_interface/sensor_descriptors.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include 9 | #include 10 | #include "cslib_sensor_descriptors.h" 11 | 12 | code char* sensorDescriptors[DEF_NUM_SENSORS] = 13 | { 14 | SENSOR_DESCRIPTOR_LIST 15 | }; 16 | 17 | void outputsensorDescriptors(void) 18 | { 19 | uint8_t index; 20 | printf("*SENSOR_DESCRIPTORS "); 21 | for(index = 0; index < DEF_NUM_SENSORS; index++) 22 | { 23 | printf("%s | ",sensorDescriptors[index]); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB1/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB3/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /efm8/efm8_util/delay.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "efm8_util/delay.h" 5 | 6 | // don't care too much if this isn't accurate 7 | void efm8_delay_us(uint16_t us) { 8 | while (us--) { 9 | __asm 10 | #if F_CPU >= 8000000ULL 11 | nop 12 | nop 13 | #endif 14 | #if F_CPU >= 16000000ULL 15 | nop 16 | nop 17 | #endif 18 | #if F_CPU >= 24000000ULL 19 | nop 20 | nop 21 | nop 22 | nop 23 | #endif 24 | #if F_CPU >= 32000000ULL 25 | nop 26 | nop 27 | nop 28 | nop 29 | #endif 30 | #if F_CPU >= 40000000ULL 31 | nop 32 | nop 33 | nop 34 | nop 35 | #endif 36 | #if F_CPU >= 48000000ULL 37 | nop 38 | nop 39 | nop 40 | nop 41 | #endif 42 | __endasm; 43 | } 44 | } 45 | 46 | void efm8_delay_ms(uint16_t ms) { 47 | while (ms--) { 48 | efm8_delay_us(1000); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/device_layer/low_power_config.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _LOW_POWER_CONFIG_H 8 | #define _LOW_POWER_CONFIG_H 9 | #include 10 | 11 | // Functions which must be defined with implementation-specific 12 | // responsibilities. These are called by LowPowerRoutines.c 13 | void CSLIB_configureSensorForSleepModeCB(void); 14 | void CSLIB_configureTimerForSleepModeCB(void); 15 | void CSLIB_configureTimerForActiveModeCB(void); 16 | void CSLIB_enterLowPowerStateCB(void); 17 | void CSLIB_checkTimerCB(void); 18 | extern xdata uint8_t timerTick; 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F380/meta-inf/appbuilder.properties: -------------------------------------------------------------------------------- 1 | frameworkId=c89051f380 2 | name=Silicon Labs C8051F380 Framework 3 | prefix=EFM8 4 | versionCategory=general 5 | architecture= 6 | #buildFileTemplates(sif930)=meta-inf/sif930.mak,meta-inf/sif930.uvopt,meta-inf/sif930.uvproj 7 | #buildFileTemplates(ezr32)=meta-inf/ezr32.mak,meta-inf/ezr32.eww,meta-inf/ezr32.ewd,meta-inf/ezr32.ewp 8 | #3buildFileTemplates(pc)=meta-inf/test.mak 9 | requiredIsdVersion=3.1.44 10 | #requiredSetups=boardHeader,callbackConfiguration,eventConfiguration,macros,additionalFiles,connectStackConfig 11 | 12 | # List of plugin option overrides 13 | #pluginOption(debug-print,usePort)=FALSE 14 | 15 | # Plugins info file, to declare virtual plugins and load the normal ones. 16 | pluginInfo=plugins.info 17 | 18 | # Location of sample apps properties file 19 | #sampleApps=../sample-apps/apps.info 20 | 21 | # Generator arguments 22 | generator.sourceroot=project 23 | generator.prependdevicename=true 24 | 25 | # Required feature level 26 | #requiredFeatureLevel=app_framework:6 27 | -------------------------------------------------------------------------------- /efm8/efm8_sfr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | // Useful defines for pin 5 | #ifndef PIN0_bm 6 | # define PIN0_bm (1<<0) 7 | # define PIN1_bm (1<<1) 8 | # define PIN2_bm (1<<2) 9 | # define PIN3_bm (1<<3) 10 | # define PIN4_bm (1<<4) 11 | # define PIN5_bm (1<<5) 12 | # define PIN6_bm (1<<6) 13 | # define PIN7_bm (1<<7) 14 | #endif 15 | 16 | #if defined(MCU_EFM8UB1) 17 | # include "EFM8UB1/inc/SI_EFM8UB1_Defs.h" 18 | # include "EFM8UB1/inc/SI_EFM8UB1_Devices.h" 19 | # include "EFM8UB1/inc/SI_EFM8UB1_Register_Enums.h" 20 | #elif defined(MCU_EFM8UB2) 21 | # include "EFM8UB2/inc/SI_EFM8UB2_Defs.h" 22 | # include "EFM8UB2/inc/SI_EFM8UB2_Devices.h" 23 | # include "EFM8UB2/inc/SI_EFM8UB2_Register_Enums.h" 24 | #elif defined(MCU_EFM8UB3) 25 | # include "EFM8UB3/inc/SI_EFM8UB3_Defs.h" 26 | # include "EFM8UB3/inc/SI_EFM8UB3_Devices.h" 27 | # include "EFM8UB3/inc/SI_EFM8UB3_Register_Enums.h" 28 | #else 29 | # warning "Device type not defined" 30 | #endif 31 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | PCA0MD |= PCA0MD_WDTE__BMASK; 12 | PCA0CPH4 = 0x00; 13 | } 14 | 15 | void WDT0_stop() 16 | { 17 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 18 | } 19 | 20 | void WDT0_feed() 21 | { 22 | PCA0CPH4 = 0x00; 23 | } 24 | 25 | void WDT0_init(uint8_t interval, 26 | WDT0_Timebase_t timebase, 27 | WDT0_IdleState_t idleState) 28 | { 29 | //Counter/Timer can not be modified when WDT enabled 30 | SLAB_ASSERT(!(PCA0MD & PCA0MD_WDTE__BMASK)); 31 | PCA0MD &= ~(PCA0MD_CPS__FMASK | PCA0MD_CIDL__BMASK); 32 | PCA0MD |= timebase + idleState; 33 | 34 | //Reload value is interval/256 35 | PCA0CPL4 = interval; 36 | } 37 | -------------------------------------------------------------------------------- /efm8/scripts/hex-size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | target_basename=`basename $1` 6 | target_dir=`dirname $1` 7 | old_hex_size_file="$target_dir/.old_hex_size-$target_basename.o" 8 | old_xram_size_file="$target_dir/.old_xram_size-$target_basename.o" 9 | 10 | code_size=$3 11 | 12 | old_hex_size=`cat "$old_hex_size_file"` 13 | hex_size=`size $1 | grep $1 | awk '{ printf $2 }'` 14 | if [[ $hex_size -eq "" ]]; then 15 | hex_size=0 16 | fi 17 | 18 | echo $hex_size > "$old_hex_size_file" 19 | printf -v size_in_hex "%x" "$hex_size" 20 | free_space16=$(($code_size - $hex_size)) 21 | echo -e "hex size: $hex_size \t0x$size_in_hex" 22 | echo "hex delta: $((hex_size - old_hex_size))" 23 | echo -e "free: $free_space16 (used $((100 * $hex_size / $code_size))% of $(($code_size)))" 24 | 25 | xram_info=$(grep "EXTERNAL RAM" $2) 26 | xram_used=$(echo $xram_info | awk '{ print $3; }') 27 | xram_total=$(echo $xram_info | awk '{ print $4; }') 28 | 29 | old_xram_size=`cat "$old_xram_size_file"` 30 | echo $xram_used > "$old_xram_size_file" 31 | echo -e "xram used: $xram_used ($((100 * $xram_used / $xram_total))% of $xram_total)" 32 | echo "xram delta: $((xram_used - old_xram_size))" 33 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/device_layer/hardware_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _HARDWARE_ROUTINES_H 8 | #define _HARDWARE_ROUTINES_H 9 | #include 10 | 11 | 12 | // Note: the functions below are hardware-specific callbacks used by the library to 13 | // perform capacitive sense scanning. All must be defined 14 | // in the project in order for the library to function correctly. 15 | uint16_t CSLIB_executeConversionCB(void); 16 | uint16_t scanSensor(uint8_t); 17 | void configureSensorForActiveMode(void); 18 | void nodeInit(uint8_t sensor_index); 19 | 20 | typedef struct 21 | { 22 | uint8_t mux; 23 | uint8_t accumulation; 24 | uint8_t gain; 25 | } TechSpecificStruct_t; 26 | 27 | 28 | extern SI_SEGMENT_VARIABLE (CSLIB_gainValues[], uint8_t, SI_SEG_CODE); 29 | extern SI_SEGMENT_VARIABLE (CSLIB_muxValues[], uint8_t, SI_SEG_CODE); 30 | extern SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[], uint8_t, SI_SEG_CODE); 31 | 32 | 33 | #define __HAS_DEVICE_LAYER 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/device_layer/hardware_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _HARDWARE_ROUTINES_H 8 | #define _HARDWARE_ROUTINES_H 9 | #include 10 | 11 | 12 | // Note: the functions below are hardware-specific callbacks used by the library to 13 | // perform capacitive sense scanning. All must be defined 14 | // in the project in order for the library to function correctly. 15 | uint16_t CSLIB_executeConversionCB(void); 16 | uint16_t scanSensor(uint8_t); 17 | void configureSensorForActiveMode(void); 18 | void nodeInit(uint8_t sensor_index); 19 | uint8_t determine_highest_gain(void); 20 | typedef struct 21 | { 22 | uint8_t mux; 23 | uint8_t accumulation; 24 | uint8_t gain; 25 | } TechSpecificStruct_t; 26 | 27 | 28 | extern SI_SEGMENT_VARIABLE (CSLIB_gainValues[], uint8_t, SI_SEG_CODE); 29 | extern SI_SEGMENT_VARIABLE (CSLIB_muxValues[], uint8_t, SI_SEG_CODE); 30 | extern SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[], uint8_t, SI_SEG_CODE); 31 | 32 | 33 | #define __HAS_DEVICE_LAYER 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/device_layer/hardware_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _HARDWARE_ROUTINES_H 8 | #define _HARDWARE_ROUTINES_H 9 | #include 10 | 11 | 12 | // Note: the functions below are hardware-specific callbacks used by the library to 13 | // perform capacitive sense scanning. All must be defined 14 | // in the project in order for the library to function correctly. 15 | uint16_t CSLIB_executeConversionCB(void); 16 | uint16_t scanSensor(uint8_t); 17 | void configureSensorForActiveMode(void); 18 | void nodeInit(uint8_t sensor_index); 19 | uint8_t determine_highest_gain(void); 20 | typedef struct 21 | { 22 | uint8_t mux; 23 | uint8_t accumulation; 24 | uint8_t gain; 25 | } TechSpecificStruct_t; 26 | 27 | 28 | extern SI_SEGMENT_VARIABLE (CSLIB_gainValues[], uint8_t, SI_SEG_CODE); 29 | extern SI_SEGMENT_VARIABLE (CSLIB_muxValues[], uint8_t, SI_SEG_CODE); 30 | extern SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[], uint8_t, SI_SEG_CODE); 31 | 32 | 33 | #define __HAS_DEVICE_LAYER 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/peripheral_driver/inc/si8_fifo.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "si8Options.h" 8 | #include "si_toolchain.h" 9 | 10 | //debug 11 | #define SI8_FIFO_USE 1 12 | 13 | #if SI8_FIFO_USE == 1 14 | 15 | /** 16 | * Structure defining a FIFO 17 | */ 18 | typedef struct si8Fifo 19 | { 20 | uint8_t* buf; //!< Poiner to user provided data buffer 21 | uint8_t head; //!< Current head position 22 | uint8_t tail; //!< Current tail position 23 | uint8_t size; //!< Size ofdata buffer 24 | }si8Fifo_t; 25 | 26 | /** 27 | * @brief push data into the fifo 28 | */ 29 | uint8_t si8_push_fifo(si8Fifo_t fifo, uint8_t* data, uint8_t size); 30 | 31 | /** 32 | * @brief pop data out of the fifo 33 | */ 34 | uint8_t si8_pop_fifo(si8Fifo_t fifo, uint8_t* data, uint8_t size); 35 | 36 | /** 37 | * Get the number of words currently in the fifo 38 | */ 39 | uint8_t si8_get_fifo_count(si8Fifo_t fifo); 40 | 41 | #if SI8_FIFO_USE_CALLBACKS == 1 42 | 43 | /** 44 | * Called when an underflow occurs 45 | */ 46 | void fifo_underflow(si8Fifo_t fifo); 47 | //CB 48 | /** 49 | * Called when an overflow occurs 50 | */ 51 | void fifo_underflow(si8Fifo_t fifo); 52 | 53 | #endif //SI8_FIFO_USE_CALLBACKS 54 | #endif //SI8_FIFO_USE 55 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB1/peripheral_driver/src/pwr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "pwr.h" 8 | 9 | void PWR_enterIdle(void) 10 | { 11 | // Set the IDLE bit followed by a 3-cycle dummy instruction to ensure the 12 | // CPU wakes under all conditions (see ref manual) 13 | PCON0 |= PCON0_IDLE__IDLE; 14 | PCON0 = PCON0; 15 | } 16 | 17 | #if (EFM8PDL_PWR_USE_STOP == 1) 18 | void PWR_enterStop(void) 19 | { 20 | // No need to service interrupts 21 | IE_EA = 0; 22 | 23 | // Clock source must be HFOSC for lowest power (see ref manual) 24 | // Enable HFOSC then source the system clock from it 25 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC; 26 | 27 | // Set the STOP bit 28 | PCON0 |= PCON0_STOP__BMASK; 29 | 30 | // NOTE: Reset is required to exit stop mode. Program execution 31 | // will not continue to this point. 32 | } 33 | #endif // EFM8PDL_PWR_USE_STOP 34 | 35 | void PWR_enterShutdown(void) 36 | { 37 | // No need to service interrupts 38 | IE_EA = 0; 39 | 40 | // Set the STOPCF bit to shutdown regulator 41 | REG0CN |= REG0CN_STOPCF__SHUTDOWN; 42 | 43 | // Set the STOP bit 44 | PCON0 |= PCON0_STOP__BMASK; 45 | 46 | // NOTE: Reset is required to exit stop mode. Program execution 47 | // will not continue to this point. 48 | } 49 | -------------------------------------------------------------------------------- /efm8/sdcc.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | CFLAGS += \ 5 | $(CDEFS) \ 6 | $(INC_PATHS) \ 7 | $(OPTIMIZATION) \ 8 | 9 | C_REL_FILES = $(patsubst %.c,$(OBJ_DIR)/%.rel,$(C_SRC)) 10 | ASM_REL_FILES = $(patsubst %.S,$(OBJ_DIR)/%.rel,$(ASM_SRC)) 11 | DEP_FILES = $(patsubst %.c,$(OBJ_DIR)/%.dep,$(C_SRC)) 12 | 13 | # REL_FILES = $(C_REL_FILES) $(ASM_REL_FILES) 14 | 15 | REL_FILES = $(C_REL_FILES) $(ASM_REL_FILES) 16 | 17 | all: $(TARGET_HEX) size 18 | 19 | $(TARGET_HEX): $(REL_FILES) 20 | @echo "=== compiling target ===" 21 | @$(CC) $(CFLAGS) $(LFLAGS) $(REL_FILES) -o $@ 22 | mv "$(TARGET).lk" "$(TARGET).map" "$(TARGET).mem" -t $(OBJ_DIR) 23 | 24 | .PHONY: 25 | size: $(TARGET_HEX) 26 | @echo "=== Size Information ($(TARGET_HEX))===" 27 | @$(EFM8_PATH)/scripts/hex-size.sh $< "$(TARG_OBJ).mem" "$(CODE_SIZE)" 28 | 29 | # rule for c 30 | $(OBJ_DIR)%.rel: 31 | @echo "compiling: $<" 32 | @mkdir -p $(dir $@) 33 | @$(CC) $(CFLAGS) -c $< -o $@ || echo "" 34 | 35 | # rule for asm 36 | $(OBJ_DIR)/%.rel: %.S 37 | @mkdir -p $(dir $@) 38 | $(AS) $(ASFLAGS) $@ $< 39 | 40 | # rule for DEP_FILES 41 | # sdcc doesn't pass the -MT flag correctly to the preprocessor, so need to 42 | # call the preprocessor directly to generate dependency files 43 | $(OBJ_DIR)/%.dep: %.c 44 | @mkdir -p $(dir $@) 45 | @$(PP) $(INC_PATHS) $(CDEFS) -MM \ 46 | -MT $(basename $@).rel $< -o $@ 47 | 48 | .PHONY: 49 | clean: 50 | rm -f $(TARGET_HEX) 51 | rm -f $(TARG_OBJ).lk 52 | rm -f $(TARG_OBJ).map 53 | rm -f $(TARG_OBJ).mem 54 | rm -fr $(OBJ_DIR) 55 | -------------------------------------------------------------------------------- /examples/blink/src/main.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | /// @file main.c 4 | /// 5 | /// Blink demo for EFM8UB2 6 | /// 7 | /// Blinks LEDs on pins P2.2 and P2.3 8 | 9 | #include "efm8_util/delay.h" 10 | #include "efm8_util/watchdog.h" 11 | 12 | #define LED0 P2_B2 13 | #define LED1 P2_B3 14 | 15 | /// Time between blinks 16 | #define BLINK_DELAY 250 17 | 18 | /// Setup io pins 19 | static void io_init() { 20 | // P0 - Skipped, Open-Drain, Digital 21 | // P1 - Skipped, Open-Drain, Digital 22 | // P2.2 - Unassigned, Push-Pull, Digital 23 | // P2.3 - Unassigned, Push-Pull, Digital 24 | 25 | P2MDOUT = PIN2_bm | PIN3_bm; 26 | P0SKIP = 0xFF; 27 | P1SKIP = 0xFF; 28 | P2SKIP = 0xFF; 29 | XBR1 = XBR1_XBARE__ENABLED; 30 | } 31 | 32 | /// Setup oscillator and flash read timings 33 | static void oscillator_init() { 34 | // Flash settings 35 | FLSCL = ( 36 | FLSCL_FOSE__ENABLED 37 | | FLSCL_FLRT__SYSCLK_BELOW_48_MHZ 38 | ); 39 | // Clock settings 40 | CLKSEL = CLKSEL_CLKSL__HFOSC; 41 | } 42 | 43 | /// Setup code 44 | void setup(void) { 45 | efm8_watchdog_disable(); 46 | 47 | oscillator_init(); 48 | io_init(); 49 | 50 | // Disable interrupts 51 | IE_EA = 0; 52 | } 53 | 54 | void main(void) { 55 | setup(); 56 | 57 | LED0 = 1; 58 | LED1 = 0; 59 | 60 | while (1) { 61 | LED0 = !LED0; 62 | efm8_delay_ms(BLINK_DELAY); 63 | LED1 = !LED1; 64 | efm8_delay_ms(BLINK_DELAY); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/serial_interface/comm_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _COMMROUTINES_H 8 | #define _COMMROUTINES_H 9 | 10 | #include 11 | 12 | 13 | typedef struct{ 14 | char* header; 15 | uint8_t instances; 16 | }HeaderStruct_t; 17 | 18 | uint8_t OutputU8(uint8_t* buffer, uint8_t lengthh, uint8_t transmitconfig); 19 | uint8_t OutputU16(uint8_t* buffer, uint8_t length, uint8_t transmitconfig); 20 | uint8_t OutputString(uint8_t* buffer); 21 | void CSLIB_commInit(void); 22 | uint16_t getU16(void); 23 | void outputHeaderCount(HeaderStruct_t); 24 | void outputBreak(void); 25 | void outputBeginHeader(void); 26 | void outputNewLine(void); 27 | 28 | void printOutputSingAct(uint16_t offset); 29 | void printOutputDebAct(uint16_t offset); 30 | void printOutputTDelta(uint16_t offset); 31 | 32 | extern idata uint8_t bufferU8[]; 33 | extern idata uint16_t bufferU16[]; 34 | 35 | void printOutput(uint16_t, uint8_t); 36 | extern uint16_t printBase; 37 | extern uint16_t printSize; 38 | extern uint16_t printCount; 39 | 40 | // Implementation-specific information 41 | #define UART_BAUDRATE (921600L) // Baud rate of UART in bps 42 | //#define UART_BAUDRATE (230400L) // Baud rate of UART in bps 43 | #define UART_SYSCLK 24500000L // SYSCLK frequency in Hz 44 | #define INCLUDE_SPACES 1 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/serial_interface/comm_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _COMMROUTINES_H 8 | #define _COMMROUTINES_H 9 | 10 | #include 11 | 12 | 13 | typedef struct{ 14 | char* header; 15 | uint8_t instances; 16 | }HeaderStruct_t; 17 | 18 | uint8_t OutputU8(uint8_t* buffer, uint8_t lengthh, uint8_t transmitconfig); 19 | uint8_t OutputU16(uint8_t* buffer, uint8_t length, uint8_t transmitconfig); 20 | uint8_t OutputString(uint8_t* buffer); 21 | void CSLIB_commInit(void); 22 | uint16_t getU16(void); 23 | void outputHeaderCount(HeaderStruct_t); 24 | void outputBreak(void); 25 | void outputBeginHeader(void); 26 | void outputNewLine(void); 27 | 28 | void printOutputSingAct(uint16_t offset); 29 | void printOutputDebAct(uint16_t offset); 30 | void printOutputTDelta(uint16_t offset); 31 | 32 | extern idata uint8_t bufferU8[]; 33 | extern idata uint16_t bufferU16[]; 34 | 35 | void printOutput(uint16_t, uint8_t); 36 | extern uint16_t printBase; 37 | extern uint16_t printSize; 38 | extern uint16_t printCount; 39 | 40 | // Implementation-specific information 41 | //#define UART_BAUDRATE (921600L) // Baud rate of UART in bps 42 | #define UART_BAUDRATE (115200L) // Baud rate of UART in bps 43 | #define UART_SYSCLK 24500000L // SYSCLK frequency in Hz 44 | #define INCLUDE_SPACES 1 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/serial_interface/comm_routines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _COMMROUTINES_H 8 | #define _COMMROUTINES_H 9 | 10 | #include 11 | 12 | 13 | typedef struct{ 14 | char* header; 15 | uint8_t instances; 16 | }HeaderStruct_t; 17 | 18 | uint8_t OutputU8(uint8_t* buffer, uint8_t lengthh, uint8_t transmitconfig); 19 | uint8_t OutputU16(uint8_t* buffer, uint8_t length, uint8_t transmitconfig); 20 | uint8_t OutputString(uint8_t* buffer); 21 | void CSLIB_commInit(void); 22 | uint16_t getU16(void); 23 | void outputHeaderCount(HeaderStruct_t); 24 | void outputBreak(void); 25 | void outputBeginHeader(void); 26 | void outputNewLine(void); 27 | 28 | void printOutputSingAct(uint16_t offset); 29 | void printOutputDebAct(uint16_t offset); 30 | void printOutputTDelta(uint16_t offset); 31 | 32 | // extern idata uint8_t bufferU8[]; 33 | // extern idata uint16_t bufferU16[]; 34 | 35 | void printOutput(uint16_t, uint8_t); 36 | extern uint16_t printBase; 37 | extern uint16_t printSize; 38 | extern uint16_t printCount; 39 | 40 | // Implementation-specific information 41 | #define UART_BAUDRATE (921600L) // Baud rate of UART in bps 42 | //#define UART_BAUDRATE (230400L) // Baud rate of UART in bps 43 | #define UART_SYSCLK 24500000L // SYSCLK frequency in Hz 44 | #define INCLUDE_SPACES 1 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB3/inc/SI_EFM8UB3_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8UB30F40G_QFN20 11 | // EFM8UB31F40G_QFN24 12 | // EFM8UB31F40G_QSOP24 13 | 14 | #ifndef SI_EFM8UB3_DEVICES_H 15 | #define SI_EFM8UB3_DEVICES_H 16 | 17 | #define EFM8UB30F40G_QFN20 0x00 18 | #define EFM8UB31F40G_QFN24 0x01 19 | #define EFM8UB31F40G_QSOP24 0x02 20 | 21 | #if (EFM8UB3_DEVICE == EFM8UB30F40G_QFN20) 22 | #define DEVICE_DERIVID EFM8UB30F40G_QFN20 23 | #define DEVICE_FLASH_SIZE 0x9E00 24 | #define DEVICE_XRAM_SIZE 0x0C00 25 | #define DEVICE_PKG_QFN20 1 26 | 27 | #elif (EFM8UB3_DEVICE == EFM8UB31F40G_QFN24) 28 | #define DEVICE_DERIVID EFM8UB31F40G_QFN24 29 | #define DEVICE_FLASH_SIZE 0x9E00 30 | #define DEVICE_XRAM_SIZE 0x0C00 31 | #define DEVICE_PKG_QFN24 1 32 | 33 | #elif (EFM8UB3_DEVICE == EFM8UB31F40G_QSOP24) 34 | #define DEVICE_DERIVID EFM8UB31F40G_QSOP24 35 | #define DEVICE_FLASH_SIZE 0x9E00 36 | #define DEVICE_XRAM_SIZE 0x0C00 37 | #define DEVICE_PKG_QSOP24 1 38 | 39 | #endif 40 | 41 | #endif // SI_EFM8UB3_DEVICES_H 42 | 43 | //-eof-------------------------------------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /efm8/si8051Base/endian.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef __ENDIAN_H__ 8 | #define __ENDIAN_H__ 9 | 10 | #define bswapu16(x) (((x) >> 8) | ((x) << 8)) 11 | #define bswapu32(x) (((x) >> 24) | (((x) & 0x00FF0000) >> 8) \ 12 | | (((x) & 0x0000FF00) << 8) | ((x) << 24)) 13 | 14 | #define bswap16(x) bswapu16((uint16_t)(x)) 15 | #define bswap32(x) bswapu32((uint32_t)(x)) 16 | 17 | // Big Endian Compilers 18 | #if ((defined __C51__) || (defined __RC51__) || (defined _CC51)) 19 | 20 | #define htobe16(x) (x) 21 | #define htobe32(x) (x) 22 | #define be16toh(x) (x) 23 | #define be32toh(x) (x) 24 | 25 | #define htole16(x) bswap16(x) 26 | #define htole32(x) bswap32(x) 27 | #define le16toh(x) bswap16(x) 28 | #define le32toh(x) bswap32(x) 29 | 30 | #elif ((defined SDCC) || (defined HI_TECH_C) || (defined __ICC8051__)) 31 | 32 | #define htobe16(x) bswap16(x) 33 | #define htobe32(x) bswap32(x) 34 | #define be16toh(x) bswap16(x) 35 | #define be32toh(x) bswap32(x) 36 | 37 | #define htole16(x) (x) 38 | #define htole32(x) (x) 39 | #define le16toh(x) (x) 40 | #define le32toh(x) (x) 41 | 42 | #else 43 | 44 | #define htobe16(x) (x) 45 | #define htobe32(x) (x) 46 | #define be16toh(x) (x) 47 | #define be32toh(x) (x) 48 | 49 | #define htole16(x) (x) 50 | #define htole32(x) (x) 51 | #define le16toh(x) (x) 52 | #define le32toh(x) (x) 53 | 54 | #endif // Compiler Definitions 55 | 56 | #endif // __ENDIAN_H__ 57 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/serial_interface/profiler_interface.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | #ifndef _DEBUG_SWITCHES_H 7 | #define _DEBUG_SWITCHES_H 8 | 9 | // NOTE these configurations are chosen in a compiler directive that assigns a 10 | // value to OUTPUT_MODE. The directive can be found and configurations 11 | // changed using the pull-down menu in Project->Target Toolchain configuration. 12 | #define RAW_ONLY 1 13 | #define FULL_OUTPUT_RX_FROM_FILE 2 14 | #define FULL_OUTPUT_RX_FROM_SENSOR 3 15 | #define SLIDER_OUTPUT_RX_FROM_SENSOR 4 16 | #define CUSTOM_OUTPUT 5 17 | 18 | #define OUTPUT_MODE FULL_OUTPUT_RX_FROM_SENSOR 19 | void CSLIB_commUpdate(void); 20 | 21 | 22 | // FULL_OUTPUT_RX_FROM_SENSOR. This setting uses real sensor data 23 | // and outputs most algorithmic data for analysis. 24 | 25 | #if OUTPUT_MODE == FULL_OUTPUT_RX_FROM_SENSOR 26 | #define RECEIVE_DATA_SENSOR 1 27 | #define RECEIVE_DATA_FILE 0 28 | 29 | #define PRINT_OUTPUTBUFFER 1 30 | #define PRINT_BUTTON_STATE 0 31 | #define PRINT_BASELINES 1 32 | #define PRINT_SLIDER 0 33 | #define PRINT_RAW 1 34 | #define PRINT_PROCESS 1 35 | #define PRINT_SINGLE_ACTIVE 1 36 | #define PRINT_DEBOUNCE_ACTIVE 1 37 | #define PRINT_TOUCH_DELTA 1 38 | #define PRINT_NOISE 1 39 | #define PRINT_EXP_VALUE 1 40 | #define PRINT_GLOBAL_NOISE_EST 1 41 | 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/serial_interface/profiler_interface.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | #ifndef _DEBUG_SWITCHES_H 7 | #define _DEBUG_SWITCHES_H 8 | 9 | // NOTE these configurations are chosen in a compiler directive that assigns a 10 | // value to OUTPUT_MODE. The directive can be found and configurations 11 | // changed using the pull-down menu in Project->Target Toolchain configuration. 12 | #define RAW_ONLY 1 13 | #define FULL_OUTPUT_RX_FROM_FILE 2 14 | #define FULL_OUTPUT_RX_FROM_SENSOR 3 15 | #define SLIDER_OUTPUT_RX_FROM_SENSOR 4 16 | #define CUSTOM_OUTPUT 5 17 | 18 | #define OUTPUT_MODE FULL_OUTPUT_RX_FROM_SENSOR 19 | void CSLIB_commUpdate(void); 20 | 21 | 22 | // FULL_OUTPUT_RX_FROM_SENSOR. This setting uses real sensor data 23 | // and outputs most algorithmic data for analysis. 24 | 25 | #if OUTPUT_MODE == FULL_OUTPUT_RX_FROM_SENSOR 26 | #define RECEIVE_DATA_SENSOR 1 27 | #define RECEIVE_DATA_FILE 0 28 | 29 | #define PRINT_OUTPUTBUFFER 1 30 | #define PRINT_BUTTON_STATE 0 31 | #define PRINT_BASELINES 1 32 | #define PRINT_SLIDER 0 33 | #define PRINT_RAW 1 34 | #define PRINT_PROCESS 1 35 | #define PRINT_SINGLE_ACTIVE 1 36 | #define PRINT_DEBOUNCE_ACTIVE 1 37 | #define PRINT_TOUCH_DELTA 1 38 | #define PRINT_NOISE 1 39 | #define PRINT_EXP_VALUE 1 40 | #define PRINT_GLOBAL_NOISE_EST 1 41 | 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/serial_interface/profiler_interface.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef _DEBUG_SWITCHES_H 8 | #define _DEBUG_SWITCHES_H 9 | 10 | // NOTE these configurations are chosen in a compiler directive that assigns a 11 | // value to OUTPUT_MODE. The directive can be found and configurations 12 | // changed using the pull-down menu in Project->Target Toolchain configuration. 13 | #define RAW_ONLY 1 14 | #define FULL_OUTPUT_RX_FROM_FILE 2 15 | #define FULL_OUTPUT_RX_FROM_SENSOR 3 16 | #define SLIDER_OUTPUT_RX_FROM_SENSOR 4 17 | #define CUSTOM_OUTPUT 5 18 | 19 | #define OUTPUT_MODE FULL_OUTPUT_RX_FROM_SENSOR 20 | void CSLIB_commUpdate(void); 21 | 22 | 23 | // FULL_OUTPUT_RX_FROM_SENSOR. This setting uses real sensor data 24 | // and outputs most algorithmic data for analysis. 25 | 26 | #if OUTPUT_MODE == FULL_OUTPUT_RX_FROM_SENSOR 27 | #define RECEIVE_DATA_SENSOR 1 28 | #define RECEIVE_DATA_FILE 0 29 | 30 | #define PRINT_OUTPUTBUFFER 1 31 | #define PRINT_BUTTON_STATE 0 32 | #define PRINT_BASELINES 1 33 | #define PRINT_SLIDER 0 34 | #define PRINT_RAW 1 35 | #define PRINT_PROCESS 0 36 | #define PRINT_SINGLE_ACTIVE 1 37 | #define PRINT_DEBOUNCE_ACTIVE 1 38 | #define PRINT_TOUCH_DELTA 1 39 | #define PRINT_NOISE 1 40 | #define PRINT_EXP_VALUE 1 41 | #define PRINT_GLOBAL_NOISE_EST 1 42 | 43 | #endif 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /efm8/boards.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | ####################################################################### 5 | # board config options # 6 | ####################################################################### 7 | 8 | # Note: Specific board configs are stored in the `boards` directory. 9 | 10 | ifndef BOARD_DIR 11 | BOARD_DIR = boards 12 | endif 13 | 14 | ifndef BOARD 15 | BOARD = default 16 | endif 17 | 18 | ifndef BUILD_DIR 19 | BUILD_DIR = build 20 | endif 21 | 22 | ifneq ("$(wildcard boards/$(BOARD)/config.mk)","") 23 | BOARD_MAKEFILE=$(BOARD_DIR)/$(BOARD)/config.mk 24 | INC_PATHS += -I$(BOARD_DIR)/$(BOARD) 25 | include $(BOARD_MAKEFILE) 26 | MAKEFILE_INC += $(BOARD_MAKEFILE) 27 | TARGET_TMP = $(TARGET_BASE_NAME)-$(BOARD) 28 | else 29 | $(error "Unknown board $(BOARD)") 30 | endif 31 | 32 | ####################################################################### 33 | # binary dirs # 34 | ####################################################################### 35 | 36 | # Object files directory 37 | OBJ_DIR = $(BUILD_DIR)/$(BOARD)/obj 38 | 39 | # Director were output files are placed 40 | BUILD_TARGET_DIR = $(BUILD_DIR)/$(BOARD) 41 | 42 | # Where dependency files are placed 43 | DEP_DIR = $(OBJ_DIR)/.dep 44 | 45 | ####################################################################### 46 | # Target output files # 47 | ####################################################################### 48 | 49 | TARG_OBJ = $(BUILD_TARGET_DIR)/obj/$(TARGET_TMP) 50 | TARGET = $(BUILD_TARGET_DIR)/$(TARGET_TMP) 51 | 52 | TARGET_HEX = $(TARGET).hex 53 | TARGET_ELF = $(TARGET).elf 54 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/efm8_capsense/device_layer/hardware_config.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include "hardware_routines.h" 9 | #include "cslib_config.h" 10 | 11 | /// @brief Derive thresholds at init based on config profile settings 12 | idata uint16_t active_thresh[DEF_NUM_SENSORS]; 13 | idata uint16_t inactive_thresh[DEF_NUM_SENSORS]; 14 | 15 | // Default values in a one-to-one mapping with the sensor node. These values 16 | // are copied into the sensor node entry for that sensor at startup. 17 | SI_SEGMENT_VARIABLE (CSLIB_muxValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 18 | { 19 | MUX_VALUE_ARRAY 20 | }; 21 | // Default values in a one-to-one mapping with the sensor node. These values 22 | // are copied into the sensor node entry for that sensor at startup. 23 | SI_SEGMENT_VARIABLE (CSLIB_gainValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 24 | { 25 | GAIN_VALUE_ARRAY 26 | }; 27 | 28 | // Default values in a one-to-one mapping with the sensor node. These values 29 | // are copied into the sensor node entry for that sensor at startup. 30 | SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 31 | { 32 | ACCUMULATION_VALUE_ARRAY 33 | }; 34 | 35 | SI_SEGMENT_VARIABLE (CSLIB_activeThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 36 | { 37 | ACTIVE_THRESHOLD_ARRAY 38 | }; 39 | SI_SEGMENT_VARIABLE (CSLIB_inactiveThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 40 | { 41 | INACTIVE_THRESHOLD_ARRAY 42 | }; 43 | 44 | SI_SEGMENT_VARIABLE (CSLIB_averageTouchDelta[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 45 | { 46 | AVERAGE_TOUCH_DELTA_ARRAY 47 | }; 48 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F990/efm8_capsense/device_layer/hardware_config.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include "hardware_routines.h" 9 | #include "cslib_config.h" 10 | 11 | /// @brief Derive thresholds at init based on config profile settings 12 | idata uint16_t active_thresh[DEF_NUM_SENSORS]; 13 | idata uint16_t inactive_thresh[DEF_NUM_SENSORS]; 14 | 15 | // Default values in a one-to-one mapping with the sensor node. These values 16 | // are copied into the sensor node entry for that sensor at startup. 17 | SI_SEGMENT_VARIABLE (CSLIB_muxValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 18 | { 19 | MUX_VALUE_ARRAY 20 | }; 21 | // Default values in a one-to-one mapping with the sensor node. These values 22 | // are copied into the sensor node entry for that sensor at startup. 23 | SI_SEGMENT_VARIABLE (CSLIB_gainValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 24 | { 25 | GAIN_VALUE_ARRAY 26 | }; 27 | 28 | // Default values in a one-to-one mapping with the sensor node. These values 29 | // are copied into the sensor node entry for that sensor at startup. 30 | SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 31 | { 32 | ACCUMULATION_VALUE_ARRAY 33 | }; 34 | 35 | SI_SEGMENT_VARIABLE (CSLIB_activeThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 36 | { 37 | ACTIVE_THRESHOLD_ARRAY 38 | }; 39 | SI_SEGMENT_VARIABLE (CSLIB_inactiveThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 40 | { 41 | INACTIVE_THRESHOLD_ARRAY 42 | }; 43 | 44 | SI_SEGMENT_VARIABLE (CSLIB_averageTouchDelta[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 45 | { 46 | AVERAGE_TOUCH_DELTA_ARRAY 47 | }; 48 | -------------------------------------------------------------------------------- /efm8/mcu/C8051F970/efm8_capsense/device_layer/hardware_config.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "cslib_hwconfig.h" 8 | #include "hardware_routines.h" 9 | #include "cslib_config.h" 10 | 11 | /// @brief Derive thresholds at init based on config profile settings 12 | idata uint16_t active_thresh[DEF_NUM_SENSORS]; 13 | idata uint16_t inactive_thresh[DEF_NUM_SENSORS]; 14 | 15 | // Default values in a one-to-one mapping with the sensor node. These values 16 | // are copied into the sensor node entry for that sensor at startup. 17 | SI_SEGMENT_VARIABLE (CSLIB_muxValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 18 | { 19 | MUX_VALUE_ARRAY 20 | }; 21 | // Default values in a one-to-one mapping with the sensor node. These values 22 | // are copied into the sensor node entry for that sensor at startup. 23 | SI_SEGMENT_VARIABLE (CSLIB_gainValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 24 | { 25 | GAIN_VALUE_ARRAY 26 | 27 | }; 28 | 29 | // Default values in a one-to-one mapping with the sensor node. These values 30 | // are copied into the sensor node entry for that sensor at startup. 31 | SI_SEGMENT_VARIABLE (CSLIB_accumulationValues[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 32 | { 33 | ACCUMULATION_VALUE_ARRAY 34 | }; 35 | 36 | SI_SEGMENT_VARIABLE (CSLIB_activeThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 37 | { 38 | ACTIVE_THRESHOLD_ARRAY 39 | }; 40 | SI_SEGMENT_VARIABLE (CSLIB_inactiveThreshold[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 41 | { 42 | INACTIVE_THRESHOLD_ARRAY 43 | }; 44 | 45 | SI_SEGMENT_VARIABLE (CSLIB_averageTouchDelta[DEF_NUM_SENSORS], uint8_t, SI_SEG_CODE) = 46 | { 47 | AVERAGE_TOUCH_DELTA_ARRAY 48 | }; 49 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/inc/SI_EFM8UB1_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8UB10F16G_QFN20 11 | // EFM8UB10F16G_QFN28 12 | // EFM8UB10F8G_QFN20 13 | // EFM8UB11F16G_QFN24 14 | // EFM8UB11F16G_QSOP24 15 | 16 | #ifndef SI_EFM8UB1_DEVICES_H 17 | #define SI_EFM8UB1_DEVICES_H 18 | 19 | #define EFM8UB10F16G_QFN20 0x43 20 | #define EFM8UB10F16G_QFN28 0x41 21 | #define EFM8UB10F8G_QFN20 0x49 22 | #define EFM8UB11F16G_QFN24 0x4A 23 | #define EFM8UB11F16G_QSOP24 0x45 24 | 25 | #if (EFM8UB1_DEVICE == EFM8UB10F16G_QFN20) 26 | #define DEVICE_DERIVID EFM8UB10F16G_QFN20 27 | #define DEVICE_FLASH_SIZE 0x4000 28 | #define DEVICE_XRAM_SIZE 0x0400 29 | #define DEVICE_PKG_QFN20 1 30 | 31 | #elif (EFM8UB1_DEVICE == EFM8UB10F16G_QFN28) 32 | #define DEVICE_DERIVID EFM8UB10F16G_QFN28 33 | #define DEVICE_FLASH_SIZE 0x4000 34 | #define DEVICE_XRAM_SIZE 0x0400 35 | #define DEVICE_PKG_QFN28 1 36 | 37 | #elif (EFM8UB1_DEVICE == EFM8UB10F8G_QFN20) 38 | #define DEVICE_DERIVID EFM8UB10F8G_QFN20 39 | #define DEVICE_FLASH_SIZE 0x2000 40 | #define DEVICE_XRAM_SIZE 0x0400 41 | #define DEVICE_PKG_QFN20 1 42 | 43 | #elif (EFM8UB1_DEVICE == EFM8UB11F16G_QFN24) 44 | #define DEVICE_DERIVID EFM8UB11F16G_QFN24 45 | #define DEVICE_FLASH_SIZE 0x4000 46 | #define DEVICE_XRAM_SIZE 0x0400 47 | #define DEVICE_PKG_QFN24 1 48 | 49 | #elif (EFM8UB1_DEVICE == EFM8UB11F16G_QSOP24) 50 | #define DEVICE_DERIVID EFM8UB11F16G_QSOP24 51 | #define DEVICE_FLASH_SIZE 0x4000 52 | #define DEVICE_XRAM_SIZE 0x0400 53 | #define DEVICE_PKG_QSOP24 1 54 | 55 | #endif 56 | 57 | #endif // SI_EFM8UB1_DEVICES_H 58 | 59 | //-eof-------------------------------------------------------------------------- 60 | 61 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | #if (EFM8PDL_WDT0_AUTO_PAGE == 1) 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | 25 | #else 26 | #define DECL_PAGE 27 | #define SET_PAGE 28 | #define RESTORE_PAGE 29 | #endif 30 | 31 | void WDT0_start(){ 32 | DECL_PAGE; 33 | SET_PAGE(0x00); 34 | PCA0MD |= PCA0MD_WDTE__BMASK; 35 | PCA0CPH2 = 0x00; 36 | RESTORE_PAGE; 37 | } 38 | 39 | void WDT0_stop() 40 | { 41 | DECL_PAGE; 42 | SET_PAGE(0x00); 43 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 44 | RESTORE_PAGE; 45 | } 46 | 47 | void WDT0_feed() 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(0x00); 51 | PCA0CPH2 = 0x00; 52 | RESTORE_PAGE; 53 | } 54 | 55 | void WDT0_init(uint8_t interval, 56 | WDT0_Timebase_t timebase, 57 | WDT0_IdleState_t idleState) 58 | { 59 | DECL_PAGE; 60 | SET_PAGE(0x00); 61 | //Counter/Timer can not be modified when WDT enabled 62 | SLAB_ASSERT(!(PCA0MD & PCA0MD_WDTE__BMASK)); 63 | PCA0MD &= ~(PCA0MD_CPS__FMASK | PCA0MD_CIDL__BMASK); 64 | PCA0MD |= timebase + idleState; 65 | 66 | //Reload value is interval/256 67 | PCA0CPL2 = interval; 68 | 69 | RESTORE_PAGE; 70 | } 71 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB2/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | #if (EFM8PDL_WDT0_AUTO_PAGE == 1) 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | 25 | #else 26 | #define DECL_PAGE 27 | #define SET_PAGE 28 | #define RESTORE_PAGE 29 | #endif 30 | 31 | void WDT0_start(){ 32 | DECL_PAGE; 33 | SET_PAGE(0x00); 34 | PCA0MD |= PCA0MD_WDTE__BMASK; 35 | PCA0CPH5 = 0x00; 36 | RESTORE_PAGE; 37 | } 38 | 39 | void WDT0_stop() 40 | { 41 | DECL_PAGE; 42 | SET_PAGE(0x00); 43 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 44 | RESTORE_PAGE; 45 | } 46 | 47 | void WDT0_feed() 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(0x00); 51 | PCA0CPH5 = 0x00; 52 | RESTORE_PAGE; 53 | } 54 | 55 | void WDT0_init(uint8_t interval, 56 | WDT0_Timebase_t timebase, 57 | WDT0_IdleState_t idleState) 58 | { 59 | DECL_PAGE; 60 | SET_PAGE(0x00); 61 | //Counter/Timer can not be modified when WDT enabled 62 | SLAB_ASSERT(!(PCA0MD & PCA0MD_WDTE__BMASK)); 63 | PCA0MD &= ~(PCA0MD_CPS__FMASK | PCA0MD_CIDL__BMASK); 64 | PCA0MD |= timebase + idleState; 65 | 66 | //Reload value is interval/256 67 | PCA0CPL5 = interval; 68 | 69 | RESTORE_PAGE; 70 | } 71 | -------------------------------------------------------------------------------- /efm8/efm8.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | VPATH += $(BASE_PATH)/src 5 | VPATH += $(EFM8_PATH) 6 | 7 | ifndef MCU 8 | $(error "MCU not defined") 9 | endif 10 | 11 | ifndef PIN_COUNT 12 | $(error "PIN_COUNT not defined") 13 | endif 14 | 15 | ifndef F_CPU 16 | $(error "F_CPU not defined") 17 | else 18 | CDEFS += -DF_CPU=$(F_CPU)ULL 19 | endif 20 | 21 | ifeq ($(MCU), EFM8UB10F16) 22 | MCU_FAMILY := EFM8UB1 23 | CODE_SIZE := 0x4000 # 16kb 24 | XRAM_SIZE := 0x0800 # 2kb 25 | else ifeq ($(MCU), EFM8UB11F16) 26 | MCU_FAMILY := EFM8UB1 27 | CODE_SIZE := 0x4000 # 16kb 28 | XRAM_SIZE := 0x0800 # 2kb 29 | else ifeq ($(MCU), EFM8UB10F16) 30 | MCU_FAMILY := EFM8UB1 31 | CODE_SIZE := 0x4000 # 16kb 32 | XRAM_SIZE := 0x0800 # 2kb 33 | else ifeq ($(MCU), EFM8UB10F8) 34 | MCU_FAMILY := EFM8UB1 35 | CODE_SIZE := 0x2000 # 8kb 36 | XRAM_SIZE := 0x0800 # 2kb 37 | else ifeq ($(MCU), EFM8UB20F32) 38 | MCU_FAMILY := EFM8UB2 39 | CODE_SIZE := 0x8000 # 32kb 40 | XRAM_SIZE := 0x0800 # 2kb 41 | else ifeq ($(MCU), EFM8UB20F64) 42 | MCU_FAMILY := EFM8UB2 43 | CODE_SIZE := 0xFC00 # 64kb 44 | XRAM_SIZE := 0x1000 # 4kb 45 | else 46 | $(error "No definition for this MCU='$(MCU)' (NOTE: must be all CAPS)"\ 47 | "TODO: not many have been defined yet") 48 | endif 49 | 50 | # TODO: check if this is true for all micros 51 | CODE_LOC := 0x0000 52 | XRAM_LOC := 0x0000 53 | 54 | CFLAGS += -DMCU_STRING=$(MCU_STRING) 55 | CFLAGS += -DPIN_COUNT=$(PIN_COUNT) 56 | CFLAGS += -DMCU_$(MCU_FAMILY) 57 | CFLAGS += -DDEVICE_$(MCU_FAMILY)=$(MCU_SPECIFIC) 58 | 59 | INC_PATHS += -I$(BASE_PATH) 60 | INC_PATHS += -I$(EFM8_PATH) 61 | INC_PATHS += -I$(EFM8_PATH)/mcu 62 | INC_PATHS += -I$(EFM8_PATH)/mcu/$(MCU_FAMILY)/inc 63 | INC_PATHS += -I$(EFM8_PATH)/mcu/$(MCU_FAMILY)/peripheral_driver/inc 64 | INC_PATHS += -I$(EFM8_PATH)/si8051Base 65 | 66 | LFLAGS += \ 67 | --code-loc $(CODE_LOC) \ 68 | --code-size $(CODE_SIZE) \ 69 | --xram-loc $(XRAM_LOC)\ 70 | --xram-size $(XRAM_SIZE) \ 71 | 72 | ifdef SIMPLICITY_STUDIO_PATH 73 | ADAPTER_PACKS_PATH="$(SIMPLICITY_STUDIO_PATH)/developer/adapter_packs" 74 | FLASH_8051="$(ADAPTER_PACKS_PATH)/c8051/flash8051" 75 | INSPECT_8051="$(ADAPTER_PACKS_PATH)/inspect_c8051/device8051" 76 | FLASH_EFM8="$(ADAPTER_PACKS_PATH)/c8051/flash8051" 77 | endif 78 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/inc/SI_EFM8UB2_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8UB20F32G_QFN32 11 | // EFM8UB20F32G_QFP32 12 | // EFM8UB20F32G_QFP48 13 | // EFM8UB20F64G_QFN32 14 | // EFM8UB20F64G_QFP32 15 | // EFM8UB20F64G_QFP48 16 | 17 | #ifndef SI_EFM8UB2_DEVICES_H 18 | #define SI_EFM8UB2_DEVICES_H 19 | 20 | #define EFM8UB20F32G_QFN32 0x65 21 | #define EFM8UB20F32G_QFP32 0x64 22 | #define EFM8UB20F32G_QFP48 0x63 23 | #define EFM8UB20F64G_QFN32 0x62 24 | #define EFM8UB20F64G_QFP32 0x61 25 | #define EFM8UB20F64G_QFP48 0x60 26 | 27 | #if (EFM8UB2_DEVICE == EFM8UB20F32G_QFN32) 28 | #define DEVICE_DERIVID EFM8UB20F32G_QFN32 29 | #define DEVICE_FLASH_SIZE 0x8000 30 | #define DEVICE_XRAM_SIZE 0x0800 31 | #define DEVICE_PKG_QFN32 1 32 | 33 | #elif (EFM8UB2_DEVICE == EFM8UB20F32G_QFP32) 34 | #define DEVICE_DERIVID EFM8UB20F32G_QFP32 35 | #define DEVICE_FLASH_SIZE 0x8000 36 | #define DEVICE_XRAM_SIZE 0x0800 37 | #define DEVICE_PKG_QFP32 1 38 | 39 | #elif (EFM8UB2_DEVICE == EFM8UB20F32G_QFP48) 40 | #define DEVICE_DERIVID EFM8UB20F32G_QFP48 41 | #define DEVICE_FLASH_SIZE 0x8000 42 | #define DEVICE_XRAM_SIZE 0x0800 43 | #define DEVICE_PKG_QFP48 1 44 | 45 | #elif (EFM8UB2_DEVICE == EFM8UB20F64G_QFN32) 46 | #define DEVICE_DERIVID EFM8UB20F64G_QFN32 47 | #define DEVICE_FLASH_SIZE 0xFC00 48 | #define DEVICE_XRAM_SIZE 0x1000 49 | #define DEVICE_PKG_QFN32 1 50 | 51 | #elif (EFM8UB2_DEVICE == EFM8UB20F64G_QFP32) 52 | #define DEVICE_DERIVID EFM8UB20F64G_QFP32 53 | #define DEVICE_FLASH_SIZE 0xFC00 54 | #define DEVICE_XRAM_SIZE 0x1000 55 | #define DEVICE_PKG_QFP32 1 56 | 57 | #elif (EFM8UB2_DEVICE == EFM8UB20F64G_QFP48) 58 | #define DEVICE_DERIVID EFM8UB20F64G_QFP48 59 | #define DEVICE_FLASH_SIZE 0xFC00 60 | #define DEVICE_XRAM_SIZE 0x1000 61 | #define DEVICE_PKG_QFP48 1 62 | 63 | #endif 64 | 65 | #endif // SI_EFM8UB2_DEVICES_H 66 | 67 | //-eof-------------------------------------------------------------------------- 68 | 69 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB4/inc/SI_EFM8UB4_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8UB40F40G_QFN20 11 | // EFM8UB41F40G_QFN20 12 | // EFM8UB42F40G_QFN24 13 | // EFM8UB42F40G_QFN32 14 | // EFM8UB42F40G_QSOP24 15 | // EFM8UB44F40G_QFN32 16 | 17 | #ifndef SI_EFM8UB4_DEVICES_H 18 | #define SI_EFM8UB4_DEVICES_H 19 | 20 | #define EFM8UB40F40G_QFN20 0x40 21 | #define EFM8UB41F40G_QFN20 0x41 22 | #define EFM8UB42F40G_QFN24 0x42 23 | #define EFM8UB42F40G_QFN32 0x44 24 | #define EFM8UB42F40G_QSOP24 0x43 25 | #define EFM8UB44F40G_QFN32 0xD0 26 | 27 | #if (EFM8UB4_DEVICE == EFM8UB40F40G_QFN20) 28 | #define DEVICE_DERIVID EFM8UB40F40G_QFN20 29 | #define DEVICE_FLASH_SIZE 0x9E00 30 | #define DEVICE_XRAM_SIZE 0x0C00 31 | #define DEVICE_PKG_QFN20 1 32 | 33 | #elif (EFM8UB4_DEVICE == EFM8UB41F40G_QFN20) 34 | #define DEVICE_DERIVID EFM8UB41F40G_QFN20 35 | #define DEVICE_FLASH_SIZE 0x9E00 36 | #define DEVICE_XRAM_SIZE 0x0C00 37 | #define DEVICE_PKG_QFN20 1 38 | 39 | #elif (EFM8UB4_DEVICE == EFM8UB42F40G_QFN24) 40 | #define DEVICE_DERIVID EFM8UB42F40G_QFN24 41 | #define DEVICE_FLASH_SIZE 0x9E00 42 | #define DEVICE_XRAM_SIZE 0x0C00 43 | #define DEVICE_PKG_QFN24 1 44 | 45 | #elif (EFM8UB4_DEVICE == EFM8UB42F40G_QFN32) 46 | #define DEVICE_DERIVID EFM8UB42F40G_QFN32 47 | #define DEVICE_FLASH_SIZE 0x9E00 48 | #define DEVICE_XRAM_SIZE 0x0C00 49 | #define DEVICE_PKG_QFN32 1 50 | 51 | #elif (EFM8UB4_DEVICE == EFM8UB42F40G_QSOP24) 52 | #define DEVICE_DERIVID EFM8UB42F40G_QSOP24 53 | #define DEVICE_FLASH_SIZE 0x9E00 54 | #define DEVICE_XRAM_SIZE 0x0C00 55 | #define DEVICE_PKG_QSOP24 1 56 | 57 | #elif (EFM8UB4_DEVICE == EFM8UB44F40G_QFN32) 58 | #define DEVICE_DERIVID EFM8UB44F40G_QFN32 59 | #define DEVICE_FLASH_SIZE 0x9E00 60 | #define DEVICE_XRAM_SIZE 0x0C00 61 | #define DEVICE_PKG_QFN32 1 62 | 63 | #endif 64 | 65 | #endif // SI_EFM8UB4_DEVICES_H 66 | 67 | //-eof-------------------------------------------------------------------------- 68 | 69 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB2/inc/SI_EFM8SB2_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8SB20F16G_QFN24 11 | // EFM8SB20F32G_QFN24 12 | // EFM8SB20F32G_QFN32 13 | // EFM8SB20F32G_QFP32 14 | // EFM8SB20F64G_QFN24 15 | // EFM8SB20F64G_QFN32 16 | // EFM8SB20F64G_QFP32 17 | 18 | #ifndef SI_EFM8SB2_DEVICES_H 19 | #define SI_EFM8SB2_DEVICES_H 20 | 21 | #define EFM8SB20F16G_QFN24 0x09 22 | #define EFM8SB20F32G_QFN24 0x06 23 | #define EFM8SB20F32G_QFN32 0x04 24 | #define EFM8SB20F32G_QFP32 0x05 25 | #define EFM8SB20F64G_QFN24 0x03 26 | #define EFM8SB20F64G_QFN32 0x01 27 | #define EFM8SB20F64G_QFP32 0x02 28 | 29 | #if (EFM8SB2_DEVICE == EFM8SB20F16G_QFN24) 30 | #define DEVICE_DERIVID EFM8SB20F16G_QFN24 31 | #define DEVICE_FLASH_SIZE 0x4000 32 | #define DEVICE_XRAM_SIZE 0x1000 33 | #define DEVICE_PKG_QFN24 1 34 | 35 | #elif (EFM8SB2_DEVICE == EFM8SB20F32G_QFN24) 36 | #define DEVICE_DERIVID EFM8SB20F32G_QFN24 37 | #define DEVICE_FLASH_SIZE 0x8000 38 | #define DEVICE_XRAM_SIZE 0x1000 39 | #define DEVICE_PKG_QFN24 1 40 | 41 | #elif (EFM8SB2_DEVICE == EFM8SB20F32G_QFN32) 42 | #define DEVICE_DERIVID EFM8SB20F32G_QFN32 43 | #define DEVICE_FLASH_SIZE 0x8000 44 | #define DEVICE_XRAM_SIZE 0x1000 45 | #define DEVICE_PKG_QFN32 1 46 | 47 | #elif (EFM8SB2_DEVICE == EFM8SB20F32G_QFP32) 48 | #define DEVICE_DERIVID EFM8SB20F32G_QFP32 49 | #define DEVICE_FLASH_SIZE 0x8000 50 | #define DEVICE_XRAM_SIZE 0x1000 51 | #define DEVICE_PKG_QFP32 1 52 | 53 | #elif (EFM8SB2_DEVICE == EFM8SB20F64G_QFN24) 54 | #define DEVICE_DERIVID EFM8SB20F64G_QFN24 55 | #define DEVICE_FLASH_SIZE 0xFC00 56 | #define DEVICE_XRAM_SIZE 0x1000 57 | #define DEVICE_PKG_QFN24 1 58 | 59 | #elif (EFM8SB2_DEVICE == EFM8SB20F64G_QFN32) 60 | #define DEVICE_DERIVID EFM8SB20F64G_QFN32 61 | #define DEVICE_FLASH_SIZE 0xFC00 62 | #define DEVICE_XRAM_SIZE 0x1000 63 | #define DEVICE_PKG_QFN32 1 64 | 65 | #elif (EFM8SB2_DEVICE == EFM8SB20F64G_QFP32) 66 | #define DEVICE_DERIVID EFM8SB20F64G_QFP32 67 | #define DEVICE_FLASH_SIZE 0xFC00 68 | #define DEVICE_XRAM_SIZE 0x1000 69 | #define DEVICE_PKG_QFP32 1 70 | 71 | #endif 72 | 73 | #endif // SI_EFM8SB2_DEVICES_H 74 | 75 | //-eof-------------------------------------------------------------------------- 76 | 77 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/dac_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_0.h" 8 | 9 | #if EFM8PDL_DAC0_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC0 (0x30) 30 | 31 | #if EFM8PDL_DAC0_USE_INIT == 1 32 | void DAC0_init(DAC0_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC0); 36 | 37 | // DAC0/1 VREF == VDD 38 | DACGCF0_D01REFSL = 1; 39 | 40 | // DAC0/1 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D01REFGN__FMASK) | DACGCF2_D01REFGN__ATTEN_2P0; 42 | DAC0CF0 = trigger; 43 | DAC0CF1 = DAC0CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC0_holdOutput(false); 46 | DAC0_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC0_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC0); 55 | DAC0CF0 |= DAC0CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC0_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC0); 63 | DAC0CF0 &= ~DAC0CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC0_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC0); 71 | // MUST load DAC0L first! 72 | DAC0L = value & 0xFF; 73 | DAC0H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC0_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC0); 81 | DACGCF1_D0UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC0_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC0); 90 | value = (DAC0H <<8) | (DAC0L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/dac_1.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_1.h" 8 | 9 | #if EFM8PDL_DAC1_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC1 (0x30) 30 | 31 | #if EFM8PDL_DAC1_USE_INIT == 1 32 | void DAC1_init(DAC1_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC1); 36 | 37 | // DAC1/1 VREF == VDD 38 | DACGCF0_D01REFSL = 1; 39 | 40 | // DAC1/1 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D01REFGN__FMASK) | DACGCF2_D01REFGN__ATTEN_2P0; 42 | DAC1CF0 = trigger; 43 | DAC1CF1 = DAC1CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC1_holdOutput(false); 46 | DAC1_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC1_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC1); 55 | DAC1CF0 |= DAC1CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC1_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC1); 63 | DAC1CF0 &= ~DAC1CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC1_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC1); 71 | // MUST load DAC1L first! 72 | DAC1L = value & 0xFF; 73 | DAC1H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC1_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC1); 81 | DACGCF1_D1UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC1_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC1); 90 | value = (DAC1H <<8) | (DAC1L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/dac_2.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_2.h" 8 | 9 | #if EFM8PDL_DAC2_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC2 (0x30) 30 | 31 | #if EFM8PDL_DAC2_USE_INIT == 1 32 | void DAC2_init(DAC2_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC2); 36 | 37 | // DAC2/3 VREF == VDD 38 | DACGCF0_D23REFSL = 1; 39 | 40 | // DAC2/3 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D23REFGN__FMASK) | DACGCF2_D23REFGN__ATTEN_2P0; 42 | DAC2CF0 = trigger; 43 | DAC2CF1 = DAC2CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC2_holdOutput(false); 46 | DAC2_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC2_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC2); 55 | DAC2CF0 |= DAC2CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC2_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC2); 63 | DAC2CF0 &= ~DAC2CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC2_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC2); 71 | // MUST load DAC2L first! 72 | DAC2L = value & 0xFF; 73 | DAC2H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC2_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC2); 81 | DACGCF1_D2UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC2_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC2); 90 | value = (DAC2H <<8) | (DAC2L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/dac_3.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_3.h" 8 | 9 | #if EFM8PDL_DAC3_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC3 (0x30) 30 | 31 | #if EFM8PDL_DAC3_USE_INIT == 1 32 | void DAC3_init(DAC3_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC3); 36 | 37 | // DAC2/3 VREF == VDD 38 | DACGCF0_D23REFSL = 1; 39 | 40 | // DAC2/3 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D23REFGN__FMASK) | DACGCF2_D23REFGN__ATTEN_2P0; 42 | DAC3CF0 = trigger; 43 | DAC3CF1 = DAC3CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC3_holdOutput(false); 46 | DAC3_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC3_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC3); 55 | DAC3CF0 |= DAC3CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC3_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC3); 63 | DAC3CF0 &= ~DAC3CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC3_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC3); 71 | // MUST load DAC3L first! 72 | DAC3L = value & 0xFF; 73 | DAC3H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC3_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC3); 81 | DACGCF1_D3UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC3_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC3); 90 | value = (DAC3H <<8) | (DAC3L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/dac_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_0.h" 8 | 9 | #if EFM8PDL_DAC0_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC0 (0x30) 30 | 31 | #if EFM8PDL_DAC0_USE_INIT == 1 32 | void DAC0_init(DAC0_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC0); 36 | 37 | // DAC0/1 VREF == VDD 38 | DACGCF0_D01REFSL = 1; 39 | 40 | // DAC0/1 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D01REFGN__FMASK) | DACGCF2_D01REFGN__ATTEN_2P0; 42 | DAC0CF0 = trigger; 43 | DAC0CF1 = DAC0CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC0_holdOutput(false); 46 | DAC0_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC0_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC0); 55 | DAC0CF0 |= DAC0CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC0_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC0); 63 | DAC0CF0 &= ~DAC0CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC0_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC0); 71 | // MUST load DAC0L first! 72 | DAC0L = value & 0xFF; 73 | DAC0H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC0_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC0); 81 | DACGCF1_D0UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC0_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC0); 90 | value = (DAC0H <<8) | (DAC0L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/dac_1.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_1.h" 8 | 9 | #if EFM8PDL_DAC1_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC1 (0x30) 30 | 31 | #if EFM8PDL_DAC1_USE_INIT == 1 32 | void DAC1_init(DAC1_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC1); 36 | 37 | // DAC1/1 VREF == VDD 38 | DACGCF0_D01REFSL = 1; 39 | 40 | // DAC1/1 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D01REFGN__FMASK) | DACGCF2_D01REFGN__ATTEN_2P0; 42 | DAC1CF0 = trigger; 43 | DAC1CF1 = DAC1CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC1_holdOutput(false); 46 | DAC1_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC1_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC1); 55 | DAC1CF0 |= DAC1CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC1_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC1); 63 | DAC1CF0 &= ~DAC1CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC1_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC1); 71 | // MUST load DAC1L first! 72 | DAC1L = value & 0xFF; 73 | DAC1H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC1_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC1); 81 | DACGCF1_D1UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC1_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC1); 90 | value = (DAC1H <<8) | (DAC1L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/dac_2.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_2.h" 8 | 9 | #if EFM8PDL_DAC2_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC2 (0x30) 30 | 31 | #if EFM8PDL_DAC2_USE_INIT == 1 32 | void DAC2_init(DAC2_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC2); 36 | 37 | // DAC2/3 VREF == VDD 38 | DACGCF0_D23REFSL = 1; 39 | 40 | // DAC2/3 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D23REFGN__FMASK) | DACGCF2_D23REFGN__ATTEN_2P0; 42 | DAC2CF0 = trigger; 43 | DAC2CF1 = DAC2CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC2_holdOutput(false); 46 | DAC2_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC2_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC2); 55 | DAC2CF0 |= DAC2CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC2_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC2); 63 | DAC2CF0 &= ~DAC2CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC2_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC2); 71 | // MUST load DAC2L first! 72 | DAC2L = value & 0xFF; 73 | DAC2H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC2_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC2); 81 | DACGCF1_D2UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC2_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC2); 90 | value = (DAC2H <<8) | (DAC2L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/dac_3.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "dac_3.h" 8 | 9 | #if EFM8PDL_DAC3_AUTO_PAGE == 1 10 | // declare variable needed for autopage enter/exit 11 | #define DECL_PAGE uint8_t savedPage 12 | // enter autopage section 13 | #define SET_PAGE(p) do \ 14 | { \ 15 | savedPage = SFRPAGE; /* save current SFR page */ \ 16 | SFRPAGE = (p); /* set SFR page */ \ 17 | } while(0) 18 | // exit autopage section 19 | #define RESTORE_PAGE do \ 20 | { \ 21 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 22 | } while(0) 23 | #else 24 | #define DECL_PAGE 25 | #define SET_PAGE(p) 26 | #define RESTORE_PAGE 27 | #endif 28 | 29 | #define SFRPAGE_DAC3 (0x30) 30 | 31 | #if EFM8PDL_DAC3_USE_INIT == 1 32 | void DAC3_init(DAC3_UpdateTrigger_t trigger) 33 | { 34 | DECL_PAGE; 35 | SET_PAGE(SFRPAGE_DAC3); 36 | 37 | // DAC2/3 VREF == VDD 38 | DACGCF0_D23REFSL = 1; 39 | 40 | // DAC2/3 VREF Buffer Attenuation / Gain = 2.0/2.0 41 | DACGCF2 = (DACGCF2 & ~DACGCF2_D23REFGN__FMASK) | DACGCF2_D23REFGN__ATTEN_2P0; 42 | DAC3CF0 = trigger; 43 | DAC3CF1 = DAC3CF1_DRVGAIN__GAIN_2P0; 44 | 45 | DAC3_holdOutput(false); 46 | DAC3_enable(); 47 | RESTORE_PAGE; 48 | } 49 | #endif 50 | 51 | void DAC3_enable(void) 52 | { 53 | DECL_PAGE; 54 | SET_PAGE(SFRPAGE_DAC3); 55 | DAC3CF0 |= DAC3CF0_EN__ENABLE; 56 | RESTORE_PAGE; 57 | } 58 | 59 | void DAC3_disable(void) 60 | { 61 | DECL_PAGE; 62 | SET_PAGE(SFRPAGE_DAC3); 63 | DAC3CF0 &= ~DAC3CF0_EN__BMASK; 64 | RESTORE_PAGE; 65 | } 66 | 67 | void DAC3_setOutput(uint16_t value) 68 | { 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_DAC3); 71 | // MUST load DAC3L first! 72 | DAC3L = value & 0xFF; 73 | DAC3H = value >> 8; 74 | RESTORE_PAGE; 75 | } 76 | 77 | void DAC3_holdOutput(bool hold) 78 | { 79 | DECL_PAGE; 80 | SET_PAGE(SFRPAGE_DAC3); 81 | DACGCF1_D3UDIS = hold; 82 | RESTORE_PAGE; 83 | } 84 | 85 | uint16_t DAC3_getOutput(void) 86 | { 87 | uint16_t value; 88 | DECL_PAGE; 89 | SET_PAGE(SFRPAGE_DAC3); 90 | value = (DAC3H <<8) | (DAC3L & 0xFF); 91 | RESTORE_PAGE; 92 | return value; 93 | } 94 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/peripheral_driver/src/pwr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "pwr.h" 8 | 9 | #if (EFM8PDL_PWR_AUTO_PAGE == 1) 10 | #define SAVE_SFRPAGE uint8_t save_sfrpage = SFRPAGE 11 | #define RESTORE_SFRPAGE SFRPAGE = save_sfrpage 12 | #else 13 | #define SAVE_SFRPAGE 14 | #define RESTORE_SFRPAGE 15 | #endif 16 | 17 | void PWR_enterIdle(void) 18 | { 19 | SAVE_SFRPAGE; 20 | SFRPAGE = 0; 21 | 22 | // Set the IDLE bit followed by a 3-cycle dummy instruction to ensure the 23 | // CPU wakes under all conditions (see ref manual) 24 | PCON0 |= PCON0_IDLE__IDLE; 25 | PCON0 = PCON0; 26 | 27 | RESTORE_SFRPAGE; 28 | } 29 | 30 | #if (EFM8PDL_PWR_USE_STOP == 1) 31 | void PWR_enterStop(void) 32 | { 33 | // No need to service interrupts or save the SFRPAGE since the device 34 | // will be stopped 35 | IE_EA = 0; 36 | SFRPAGE = 0; 37 | 38 | // Clock source must be HFOSC0 for lowest power (see ref manual) 39 | // Enable HFOSC0 then source the system clock from it 40 | HFO0CN |= HFO0CN_IOSCEN__ENABLED; 41 | CLKSEL = CLKSEL_CLKSL__HFOSC; 42 | 43 | // Set the STOP bit 44 | PCON0 |= PCON0_STOP__BMASK; 45 | 46 | // NOTE: Reset is required to exit stop mode. Program execution 47 | // will not continue to this point. 48 | } 49 | #endif // EFM8PDL_PWR_USE_STOP 50 | 51 | #include "bsp.h" 52 | 53 | void PWR_enterSuspend(void) 54 | { 55 | uint8_t save_ie, save_clksel; 56 | SAVE_SFRPAGE; 57 | SFRPAGE = 0; 58 | 59 | // Disable interrupts until the system is awake and restored 60 | save_ie = IE; 61 | IE_EA = 0; 62 | 63 | // System clock must be HFOSC to halt CPU (see ref manual) 64 | // Set the system clock to HFOSC / 1 65 | save_clksel = CLKSEL; 66 | HFO0CN |= HFO0CN_IOSCEN__ENABLED; 67 | CLKSEL = CLKSEL_CLKSL__HFOSC; 68 | 69 | // Enter suspend mode 70 | HFO0CN |= HFO0CN_SUSPEND__ENABLED; 71 | 72 | // Next restore the system clock source and divider 73 | CLKSEL = save_clksel; 74 | 75 | // Finally restore the interrupt enable 76 | IE = save_ie; 77 | RESTORE_SFRPAGE; 78 | } 79 | 80 | void PWR_enterShutdown(void) 81 | { 82 | // No need to service interrupts or save the SFRPAGE since the device 83 | // will be stopped 84 | IE_EA = 0; 85 | 86 | // Set the STOPCF bit to shutdown regulator 87 | REG01CN |= REG01CN_STOPCF__SHUTDOWN; 88 | 89 | // Set the STOP bit 90 | PCON0 |= PCON0_STOP__BMASK; 91 | 92 | // NOTE: Reset is required to exit stop mode. Program execution 93 | // will not continue to this point. 94 | } 95 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB1/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | 39 | // Disable Timer 3 interrupts 40 | EIE1 &= ~EIE1_ET3__BMASK; 41 | 42 | ticks = Ticks; 43 | 44 | // Enable Timer 3 interrupts 45 | EIE1 |= EIE1_ET3__BMASK; 46 | 47 | return ticks; 48 | } 49 | 50 | //--------------------------------------------------------------------------- 51 | // Wait 52 | //--------------------------------------------------------------------------- 53 | // 54 | // Description - Wait the specified number of milliseconds 55 | // 56 | // ms - The number of milliseconds to wait 57 | // 58 | void Wait(uint16_t ms) 59 | { 60 | uint16_t ticks = GetTickCount(); 61 | 62 | while ((GetTickCount() - ticks) < ms); 63 | } 64 | 65 | //----------------------------------------------------------------------------- 66 | // TIMER3_ISR 67 | //----------------------------------------------------------------------------- 68 | // 69 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 70 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 71 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 72 | // 73 | //----------------------------------------------------------------------------- 74 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 75 | { 76 | // Overflows every 1 ms 77 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 78 | 79 | Ticks++; 80 | } 81 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB2/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | 39 | // Disable Timer 3 interrupts 40 | EIE1 &= ~EIE1_ET3__BMASK; 41 | 42 | ticks = Ticks; 43 | 44 | // Enable Timer 3 interrupts 45 | EIE1 |= EIE1_ET3__BMASK; 46 | 47 | return ticks; 48 | } 49 | 50 | //--------------------------------------------------------------------------- 51 | // Wait 52 | //--------------------------------------------------------------------------- 53 | // 54 | // Description - Wait the specified number of milliseconds 55 | // 56 | // ms - The number of milliseconds to wait 57 | // 58 | void Wait(uint16_t ms) 59 | { 60 | uint16_t ticks = GetTickCount(); 61 | 62 | while ((GetTickCount() - ticks) < ms); 63 | } 64 | 65 | //----------------------------------------------------------------------------- 66 | // TIMER3_ISR 67 | //----------------------------------------------------------------------------- 68 | // 69 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 70 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 71 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 72 | // 73 | //----------------------------------------------------------------------------- 74 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 75 | { 76 | // Overflows every 1 ms 77 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 78 | 79 | Ticks++; 80 | } 81 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | 39 | // Disable Timer 3 interrupts 40 | EIE1 &= ~EIE1_ET3__BMASK; 41 | 42 | ticks = Ticks; 43 | 44 | // Enable Timer 3 interrupts 45 | EIE1 |= EIE1_ET3__BMASK; 46 | 47 | return ticks; 48 | } 49 | 50 | //--------------------------------------------------------------------------- 51 | // Wait 52 | //--------------------------------------------------------------------------- 53 | // 54 | // Description - Wait the specified number of milliseconds 55 | // 56 | // ms - The number of milliseconds to wait 57 | // 58 | void Wait(uint16_t ms) 59 | { 60 | uint16_t ticks = GetTickCount(); 61 | 62 | while ((GetTickCount() - ticks) < ms); 63 | } 64 | 65 | //----------------------------------------------------------------------------- 66 | // TIMER3_ISR 67 | //----------------------------------------------------------------------------- 68 | // 69 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 70 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 71 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 72 | // 73 | //----------------------------------------------------------------------------- 74 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 75 | { 76 | // Overflows every 1 ms 77 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 78 | 79 | Ticks++; 80 | } 81 | -------------------------------------------------------------------------------- /examples/blink/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | TARGET_BASE_NAME = blink 5 | MCU = EFM8UB20F32 6 | MCU_SPECIFIC = EFM8UB20F32G_QFP32 7 | PIN_COUNT = 32 8 | F_CPU = 48000000 9 | 10 | EFM8_PATH = ../../efm8 11 | BASE_PATH = . 12 | 13 | # Provide install location of Simplicity Studio for CLI flashing tools 14 | SIMPLICITY_STUDIO_PATH = $(HOME)/local/simplicity_studio/SimplicityStudio_v4 15 | 16 | ####################################################################### 17 | # programing # 18 | ####################################################################### 19 | 20 | ifndef SERIAL_NUM 21 | # The serial number of the device to program 22 | # Can also be passed on the command line 23 | SERIAL_NUM = EC3005481E8 24 | endif 25 | 26 | ####################################################################### 27 | # boards # 28 | ####################################################################### 29 | 30 | include $(EFM8_PATH)/boards.mk 31 | 32 | ####################################################################### 33 | # source files # 34 | ####################################################################### 35 | 36 | include $(EFM8_PATH)/efm8.mk 37 | 38 | # project source 39 | C_SRC += \ 40 | main.c \ 41 | 42 | # lib source 43 | C_SRC += \ 44 | efm8_util/delay.c \ 45 | 46 | ASM_SRC = \ 47 | # crtxinit.S \ 48 | 49 | ####################################################################### 50 | # compiler settings # 51 | ####################################################################### 52 | 53 | # Using optimize for speed can result in a smaller binary in sdcc 54 | # OPTIMIZATION = --opt-code-speed 55 | OPTIMIZATION = --opt-code-size 56 | 57 | # Compiler, assembler and preprocessor to use 58 | AS = sdas8051 59 | CC = sdcc 60 | PP = sdcpp 61 | 62 | # Extra compiler options 63 | CFLAGS += \ 64 | --fomit-frame-pointer \ 65 | --model-small \ 66 | # --model-large \ 67 | # --stack-auto \ 68 | # --Werror \ 69 | # --code-movx \ 70 | # --disable-warning 85 \ 71 | 72 | # Extra linking options 73 | LFLAGS += \ 74 | --iram-size 0x100 \ 75 | --stack-loc 0x080 \ 76 | --stack-size 0x060 \ 77 | # --parms-in-bank1 78 | 79 | # Assembler options 80 | ASFLAGS = -xglospff 81 | 82 | ####################################################################### 83 | # recipes # 84 | ####################################################################### 85 | 86 | include $(EFM8_PATH)/sdcc.mk 87 | include $(EFM8_PATH)/efm8_program.mk 88 | 89 | -include $(DEP_FILES) 90 | 91 | .PHONY: clean flash program all size 92 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | 39 | // Disable Timer 3 interrupts 40 | EIE1 &= ~EIE1_ET3__BMASK; 41 | 42 | ticks = Ticks; 43 | 44 | // Enable Timer 3 interrupts 45 | EIE1 |= EIE1_ET3__BMASK; 46 | 47 | return ticks; 48 | } 49 | 50 | //--------------------------------------------------------------------------- 51 | // Wait 52 | //--------------------------------------------------------------------------- 53 | // 54 | // Description - Wait the specified number of milliseconds 55 | // 56 | // ms - The number of milliseconds to wait 57 | // 58 | void Wait(uint16_t ms) 59 | { 60 | uint16_t ticks = GetTickCount(); 61 | 62 | while ((GetTickCount() - ticks) < ms); 63 | } 64 | 65 | //----------------------------------------------------------------------------- 66 | // TIMER3_ISR 67 | //----------------------------------------------------------------------------- 68 | // 69 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 70 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 71 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 72 | // 73 | // SFRPAGE automatically pushed/popped and set to 0x10 74 | // 75 | //----------------------------------------------------------------------------- 76 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 77 | { 78 | // Overflows every 1 ms 79 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 80 | 81 | Ticks++; 82 | } 83 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/inc/SI_EFM8SB1_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8SB10F2G_QFN20 11 | // EFM8SB10F4G_QFN20 12 | // EFM8SB10F8A_QFN20 13 | // EFM8SB10F8A_QFN24 14 | // EFM8SB10F8G_CSP16 15 | // EFM8SB10F8G_QFN20 16 | // EFM8SB10F8G_QFN24 17 | // EFM8SB10F8G_QSOP24 18 | 19 | #ifndef SI_EFM8SB1_DEVICES_H 20 | #define SI_EFM8SB1_DEVICES_H 21 | 22 | #define EFM8SB10F2G_QFN20 0x09 23 | #define EFM8SB10F4G_QFN20 0x06 24 | #define EFM8SB10F8A_QFN20 0x23 25 | #define EFM8SB10F8A_QFN24 0x21 26 | #define EFM8SB10F8G_CSP16 0x0A 27 | #define EFM8SB10F8G_QFN20 0x03 28 | #define EFM8SB10F8G_QFN24 0x01 29 | #define EFM8SB10F8G_QSOP24 0x02 30 | 31 | #if (EFM8SB1_DEVICE == EFM8SB10F2G_QFN20) 32 | #define DEVICE_DERIVID EFM8SB10F2G_QFN20 33 | #define DEVICE_FLASH_SIZE 0x0800 34 | #define DEVICE_XRAM_SIZE 0x0000 35 | #define DEVICE_PKG_QFN20 1 36 | 37 | #elif (EFM8SB1_DEVICE == EFM8SB10F4G_QFN20) 38 | #define DEVICE_DERIVID EFM8SB10F4G_QFN20 39 | #define DEVICE_FLASH_SIZE 0x1000 40 | #define DEVICE_XRAM_SIZE 0x0100 41 | #define DEVICE_PKG_QFN20 1 42 | 43 | #elif (EFM8SB1_DEVICE == EFM8SB10F8A_QFN20) 44 | #define DEVICE_DERIVID EFM8SB10F8A_QFN20 45 | #define DEVICE_FLASH_SIZE 0x2000 46 | #define DEVICE_XRAM_SIZE 0x0100 47 | #define DEVICE_PKG_QFN20 1 48 | 49 | #elif (EFM8SB1_DEVICE == EFM8SB10F8A_QFN24) 50 | #define DEVICE_DERIVID EFM8SB10F8A_QFN24 51 | #define DEVICE_FLASH_SIZE 0x2000 52 | #define DEVICE_XRAM_SIZE 0x0100 53 | #define DEVICE_PKG_QFN24 1 54 | 55 | #elif (EFM8SB1_DEVICE == EFM8SB10F8G_CSP16) 56 | #define DEVICE_DERIVID EFM8SB10F8G_CSP16 57 | #define DEVICE_FLASH_SIZE 0x2000 58 | #define DEVICE_XRAM_SIZE 0x0100 59 | #define DEVICE_PKG_CSP16 1 60 | 61 | #elif (EFM8SB1_DEVICE == EFM8SB10F8G_QFN20) 62 | #define DEVICE_DERIVID EFM8SB10F8G_QFN20 63 | #define DEVICE_FLASH_SIZE 0x2000 64 | #define DEVICE_XRAM_SIZE 0x0100 65 | #define DEVICE_PKG_QFN20 1 66 | 67 | #elif (EFM8SB1_DEVICE == EFM8SB10F8G_QFN24) 68 | #define DEVICE_DERIVID EFM8SB10F8G_QFN24 69 | #define DEVICE_FLASH_SIZE 0x2000 70 | #define DEVICE_XRAM_SIZE 0x0100 71 | #define DEVICE_PKG_QFN24 1 72 | 73 | #elif (EFM8SB1_DEVICE == EFM8SB10F8G_QSOP24) 74 | #define DEVICE_DERIVID EFM8SB10F8G_QSOP24 75 | #define DEVICE_FLASH_SIZE 0x2000 76 | #define DEVICE_XRAM_SIZE 0x0100 77 | #define DEVICE_PKG_QSOP24 1 78 | 79 | #endif 80 | 81 | #endif // SI_EFM8SB1_DEVICES_H 82 | 83 | //-eof-------------------------------------------------------------------------- 84 | 85 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | uint8_t save_page = SFRPAGE; 39 | 40 | // Disable Timer 3 interrupts 41 | SFRPAGE = 0x00; 42 | EIE1 &= ~EIE1_ET3__BMASK; 43 | 44 | ticks = Ticks; 45 | 46 | // Enable Timer 3 interrupts 47 | EIE1 |= EIE1_ET3__BMASK; 48 | SFRPAGE = save_page; 49 | 50 | return ticks; 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | // Wait 55 | //--------------------------------------------------------------------------- 56 | // 57 | // Description - Wait the specified number of milliseconds 58 | // 59 | // ms - The number of milliseconds to wait 60 | // 61 | void Wait(uint16_t ms) 62 | { 63 | uint16_t ticks = GetTickCount(); 64 | 65 | while ((GetTickCount() - ticks) < ms); 66 | } 67 | 68 | //----------------------------------------------------------------------------- 69 | // TIMER3_ISR 70 | //----------------------------------------------------------------------------- 71 | // 72 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 73 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 74 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 75 | // 76 | // SFRPAGE automatically pushed/popped and set to 0x10 77 | // 78 | //----------------------------------------------------------------------------- 79 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 80 | { 81 | // Overflows every 1 ms 82 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 83 | 84 | Ticks++; 85 | } 86 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | uint8_t save_page = SFRPAGE; 39 | 40 | // Disable Timer 3 interrupts 41 | SFRPAGE = 0x10; 42 | EIE1 &= ~EIE1_ET3__BMASK; 43 | 44 | ticks = Ticks; 45 | 46 | // Enable Timer 3 interrupts 47 | EIE1 |= EIE1_ET3__BMASK; 48 | SFRPAGE = save_page; 49 | 50 | return ticks; 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | // Wait 55 | //--------------------------------------------------------------------------- 56 | // 57 | // Description - Wait the specified number of milliseconds 58 | // 59 | // ms - The number of milliseconds to wait 60 | // 61 | void Wait(uint16_t ms) 62 | { 63 | uint16_t ticks = GetTickCount(); 64 | 65 | while ((GetTickCount() - ticks) < ms); 66 | } 67 | 68 | //----------------------------------------------------------------------------- 69 | // TIMER3_ISR 70 | //----------------------------------------------------------------------------- 71 | // 72 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 73 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 74 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 75 | // 76 | // SFRPAGE automatically pushed/popped and set to 0x10 77 | // 78 | //----------------------------------------------------------------------------- 79 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 80 | { 81 | // Overflows every 1 ms 82 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 83 | 84 | Ticks++; 85 | } 86 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/bsp/efm8_memory_lcd/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | uint8_t save_page = SFRPAGE; 39 | 40 | // Disable Timer 3 interrupts 41 | SFRPAGE = 0x00; 42 | EIE1 &= ~EIE1_ET3__BMASK; 43 | 44 | ticks = Ticks; 45 | 46 | // Enable Timer 3 interrupts 47 | EIE1 |= EIE1_ET3__BMASK; 48 | SFRPAGE = save_page; 49 | 50 | return ticks; 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | // Wait 55 | //--------------------------------------------------------------------------- 56 | // 57 | // Description - Wait the specified number of milliseconds 58 | // 59 | // ms - The number of milliseconds to wait 60 | // 61 | void Wait(uint16_t ms) 62 | { 63 | uint16_t ticks = GetTickCount(); 64 | 65 | while ((GetTickCount() - ticks) < ms); 66 | } 67 | 68 | //----------------------------------------------------------------------------- 69 | // TIMER3_ISR 70 | //----------------------------------------------------------------------------- 71 | // 72 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 73 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 74 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 75 | // 76 | // SFRPAGE automatically pushed/popped and set to 0x10 77 | // 78 | //----------------------------------------------------------------------------- 79 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 80 | { 81 | // Overflows every 1 ms 82 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 83 | 84 | Ticks++; 85 | } 86 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/bsp/efm8_memory_lcd/source/tick.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Tick.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | // Includes 12 | ///////////////////////////////////////////////////////////////////////////// 13 | 14 | #include "bsp.h" 15 | #include "tick.h" 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // Globals 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 21 | static volatile uint16_t Ticks = 0; 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // Functions 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | //--------------------------------------------------------------------------- 28 | // GetTickCount 29 | //--------------------------------------------------------------------------- 30 | // 31 | // Description - Return the system up time in milliseconds 32 | // 33 | // return - Number of milliseconds since system start. 34 | // 35 | uint16_t GetTickCount() 36 | { 37 | uint16_t ticks; 38 | uint8_t save_page = SFRPAGE; 39 | 40 | // Disable Timer 3 interrupts 41 | SFRPAGE = 0x10; 42 | EIE1 &= ~EIE1_ET3__BMASK; 43 | 44 | ticks = Ticks; 45 | 46 | // Enable Timer 3 interrupts 47 | EIE1 |= EIE1_ET3__BMASK; 48 | SFRPAGE = save_page; 49 | 50 | return ticks; 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | // Wait 55 | //--------------------------------------------------------------------------- 56 | // 57 | // Description - Wait the specified number of milliseconds 58 | // 59 | // ms - The number of milliseconds to wait 60 | // 61 | void Wait(uint16_t ms) 62 | { 63 | uint16_t ticks = GetTickCount(); 64 | 65 | while ((GetTickCount() - ticks) < ms); 66 | } 67 | 68 | //----------------------------------------------------------------------------- 69 | // TIMER3_ISR 70 | //----------------------------------------------------------------------------- 71 | // 72 | // TIMER3 ISR Content goes here. Remember to clear flag bits: 73 | // TMR3CN::TF3H (Timer # High Byte Overflow Flag) 74 | // TMR3CN::TF3L (Timer # Low Byte Overflow Flag) 75 | // 76 | // SFRPAGE automatically pushed/popped and set to 0x10 77 | // 78 | //----------------------------------------------------------------------------- 79 | SI_INTERRUPT (TIMER3_ISR, TIMER3_IRQn) 80 | { 81 | // Overflows every 1 ms 82 | TMR3CN0 &= ~TMR3CN0_TF3H__BMASK; 83 | 84 | Ticks++; 85 | } 86 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/inc/SI_EFM8BB2_Devices.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // Copyright 2014 Silicon Laboratories, Inc. 3 | // All rights reserved. This program and the accompanying materials 4 | // are made available under the terms of the Silicon Laboratories End User 5 | // License Agreement which accompanies this distribution, and is available at 6 | // http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 7 | // Original content and implementation provided by Silicon Laboratories. 8 | //------------------------------------------------------------------------------ 9 | //Supported Devices: 10 | // EFM8BB21F16A_QFN20 11 | // EFM8BB21F16G_QFN20 12 | // EFM8BB21F16G_QSOP24 13 | // EFM8BB21F16I_QFN20 14 | // EFM8BB21F16I_QSOP24 15 | // EFM8BB22F16A_QFN28 16 | // EFM8BB22F16G_QFN28 17 | // EFM8BB22F16I_QFN28 18 | 19 | #ifndef SI_EFM8BB2_DEVICES_H 20 | #define SI_EFM8BB2_DEVICES_H 21 | 22 | #define EFM8BB21F16A_QFN20 0x23 23 | #define EFM8BB21F16G_QFN20 0x03 24 | #define EFM8BB21F16G_QSOP24 0x02 25 | #define EFM8BB21F16I_QFN20 0x13 26 | #define EFM8BB21F16I_QSOP24 0x12 27 | #define EFM8BB22F16A_QFN28 0x21 28 | #define EFM8BB22F16G_QFN28 0x01 29 | #define EFM8BB22F16I_QFN28 0x11 30 | 31 | #if (EFM8BB2_DEVICE == EFM8BB21F16A_QFN20) 32 | #define DEVICE_DERIVID EFM8BB21F16A_QFN20 33 | #define DEVICE_FLASH_SIZE 0x4000 34 | #define DEVICE_XRAM_SIZE 0x0800 35 | #define DEVICE_PKG_QFN20 1 36 | 37 | #elif (EFM8BB2_DEVICE == EFM8BB21F16G_QFN20) 38 | #define DEVICE_DERIVID EFM8BB21F16G_QFN20 39 | #define DEVICE_FLASH_SIZE 0x4000 40 | #define DEVICE_XRAM_SIZE 0x0800 41 | #define DEVICE_PKG_QFN20 1 42 | 43 | #elif (EFM8BB2_DEVICE == EFM8BB21F16G_QSOP24) 44 | #define DEVICE_DERIVID EFM8BB21F16G_QSOP24 45 | #define DEVICE_FLASH_SIZE 0x4000 46 | #define DEVICE_XRAM_SIZE 0x0800 47 | #define DEVICE_PKG_QSOP24 1 48 | 49 | #elif (EFM8BB2_DEVICE == EFM8BB21F16I_QFN20) 50 | #define DEVICE_DERIVID EFM8BB21F16I_QFN20 51 | #define DEVICE_FLASH_SIZE 0x4000 52 | #define DEVICE_XRAM_SIZE 0x0800 53 | #define DEVICE_PKG_QFN20 1 54 | 55 | #elif (EFM8BB2_DEVICE == EFM8BB21F16I_QSOP24) 56 | #define DEVICE_DERIVID EFM8BB21F16I_QSOP24 57 | #define DEVICE_FLASH_SIZE 0x4000 58 | #define DEVICE_XRAM_SIZE 0x0800 59 | #define DEVICE_PKG_QSOP24 1 60 | 61 | #elif (EFM8BB2_DEVICE == EFM8BB22F16A_QFN28) 62 | #define DEVICE_DERIVID EFM8BB22F16A_QFN28 63 | #define DEVICE_FLASH_SIZE 0x4000 64 | #define DEVICE_XRAM_SIZE 0x0800 65 | #define DEVICE_PKG_QFN28 1 66 | 67 | #elif (EFM8BB2_DEVICE == EFM8BB22F16G_QFN28) 68 | #define DEVICE_DERIVID EFM8BB22F16G_QFN28 69 | #define DEVICE_FLASH_SIZE 0x4000 70 | #define DEVICE_XRAM_SIZE 0x0800 71 | #define DEVICE_PKG_QFN28 1 72 | 73 | #elif (EFM8BB2_DEVICE == EFM8BB22F16I_QFN28) 74 | #define DEVICE_DERIVID EFM8BB22F16I_QFN28 75 | #define DEVICE_FLASH_SIZE 0x4000 76 | #define DEVICE_XRAM_SIZE 0x0800 77 | #define DEVICE_PKG_QFN28 1 78 | 79 | #endif 80 | 81 | #endif // SI_EFM8BB2_DEVICES_H 82 | 83 | //-eof-------------------------------------------------------------------------- 84 | 85 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/cl_0_isr.c: -------------------------------------------------------------------------------- 1 | 2 | #include "efm8_config.h" 3 | #include "SI_EFM8BB3_Register_Enums.h" 4 | 5 | #if !defined(EFM8PDL_CLU0_USE_ISR) 6 | #define EFM8PDL_CLU0_USE_ISR 0 7 | #endif 8 | 9 | #if !defined(EFM8PDL_CLU1_USE_ISR) 10 | #define EFM8PDL_CLU1_USE_ISR 0 11 | #endif 12 | 13 | #if !defined(EFM8PDL_CLU2_USE_ISR) 14 | #define EFM8PDL_CLU2_USE_ISR 0 15 | #endif 16 | 17 | #if !defined(EFM8PDL_CLU3_USE_ISR) 18 | #define EFM8PDL_CLU3_USE_ISR 0 19 | #endif 20 | 21 | #if EFM8PDL_CLU0_USE_ISR == 1 22 | #include "clu_0.h" 23 | #endif 24 | 25 | #if EFM8PDL_CLU1_USE_ISR == 1 26 | #include "clu_1.h" 27 | #endif 28 | 29 | #if EFM8PDL_CLU2_USE_ISR == 1 30 | #include "clu_2.h" 31 | #endif 32 | 33 | #if EFM8PDL_CLU3_USE_ISR == 1 34 | #include "clu_3.h" 35 | #endif 36 | 37 | #define CLU0_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C0FIE__BMASK) 38 | #define CLU0_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C0RIE__BMASK) 39 | #define CLU1_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C1FIE__BMASK) 40 | #define CLU1_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C1RIE__BMASK) 41 | #define CLU2_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C2FIE__BMASK) 42 | #define CLU2_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C2RIE__BMASK) 43 | #define CLU3_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C3FIE__BMASK) 44 | #define CLU3_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C3RIE__BMASK) 45 | 46 | #if EFM8PDL_CLU0_USE_ISR || EFM8PDL_CLU1_USE_ISR || EFM8PDL_CLU2_USE_ISR || EFM8PDL_CLU3_USE_ISR 47 | //----------------------------------------------------------------------------- 48 | // CL0_ISR 49 | //----------------------------------------------------------------------------- 50 | // 51 | // CL0 ISR Content goes here. Remember to clear flag bits: 52 | // CLIF0::C0FIF (CLU0 Falling Edge Interrupt Flag) 53 | // CLIF0::C0RIF (CLU0 Rising Edge Interrupt Flag) 54 | // CLIF0::C1FIF (CLU1 Falling Edge Interrupt Flag) 55 | // CLIF0::C1RIF (CLU1 Rising Edge Interrupt Flag) 56 | // CLIF0::C2FIF (CLU2 Falling Edge Interrupt Flag) 57 | // CLIF0::C2RIF (CLU2 Rising Edge Interrupt Flag) 58 | // CLIF0::C3FIF (CLU3 Falling Edge Interrupt Flag) 59 | // CLIF0::C3RIF (CLU3 Rising Edge Interrupt Flag) 60 | // 61 | //----------------------------------------------------------------------------- 62 | SI_INTERRUPT (CL0_ISR, CL0_IRQn) 63 | { 64 | uint8_t flags = CLIF0; 65 | CLIF0 = 0; 66 | 67 | #if EFM8PDL_CLU0_USE_ISR 68 | if ((flags & CLIF0_C0FIF__BMASK) && CLU0_RISING_EDGE_ENABLED) 69 | { 70 | CLU0_fallingEdgeCb(); 71 | } 72 | 73 | if ((flags & CLIF0_C0RIF__BMASK) && CLU0_FALLING_EDGE_ENABLED) 74 | { 75 | CLU0_risingEdgeCb(); 76 | } 77 | #endif 78 | 79 | #if EFM8PDL_CLU1_USE_ISR 80 | if ((flags & CLIF0_C1FIF__BMASK) && CLU1_RISING_EDGE_ENABLED) 81 | { 82 | CLU1_fallingEdgeCb(); 83 | } 84 | 85 | if ((flags & CLIF0_C1RIF__BMASK) && CLU1_FALLING_EDGE_ENABLED) 86 | { 87 | CLU1_risingEdgeCb(); 88 | } 89 | #endif 90 | 91 | #if EFM8PDL_CLU2_USE_ISR 92 | if ((flags & CLIF0_C2FIF__BMASK) && CLU2_RISING_EDGE_ENABLED) 93 | { 94 | CLU2_fallingEdgeCb(); 95 | } 96 | 97 | if ((flags & CLIF0_C2RIF__BMASK) && CLU2_FALLING_EDGE_ENABLED) 98 | { 99 | CLU2_risingEdgeCb(); 100 | } 101 | #endif 102 | 103 | #if EFM8PDL_CLU3_USE_ISR 104 | if ((flags & CLIF0_C3FIF__BMASK) && CLU3_RISING_EDGE_ENABLED) 105 | { 106 | CLU3_fallingEdgeCb(); 107 | } 108 | 109 | if ((flags & CLIF0_C3RIF__BMASK) && CLU3_FALLING_EDGE_ENABLED) 110 | { 111 | CLU3_risingEdgeCb(); 112 | } 113 | #endif 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/cl_0_isr.c: -------------------------------------------------------------------------------- 1 | 2 | #include "efm8_config.h" 3 | #include "SI_EFM8LB1_Register_Enums.h" 4 | 5 | #if !defined(EFM8PDL_CLU0_USE_ISR) 6 | #define EFM8PDL_CLU0_USE_ISR 0 7 | #endif 8 | 9 | #if !defined(EFM8PDL_CLU1_USE_ISR) 10 | #define EFM8PDL_CLU1_USE_ISR 0 11 | #endif 12 | 13 | #if !defined(EFM8PDL_CLU2_USE_ISR) 14 | #define EFM8PDL_CLU2_USE_ISR 0 15 | #endif 16 | 17 | #if !defined(EFM8PDL_CLU3_USE_ISR) 18 | #define EFM8PDL_CLU3_USE_ISR 0 19 | #endif 20 | 21 | #if EFM8PDL_CLU0_USE_ISR == 1 22 | #include "clu_0.h" 23 | #endif 24 | 25 | #if EFM8PDL_CLU1_USE_ISR == 1 26 | #include "clu_1.h" 27 | #endif 28 | 29 | #if EFM8PDL_CLU2_USE_ISR == 1 30 | #include "clu_2.h" 31 | #endif 32 | 33 | #if EFM8PDL_CLU3_USE_ISR == 1 34 | #include "clu_3.h" 35 | #endif 36 | 37 | #define CLU0_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C0FIE__BMASK) 38 | #define CLU0_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C0RIE__BMASK) 39 | #define CLU1_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C1FIE__BMASK) 40 | #define CLU1_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C1RIE__BMASK) 41 | #define CLU2_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C2FIE__BMASK) 42 | #define CLU2_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C2RIE__BMASK) 43 | #define CLU3_RISING_EDGE_ENABLED (CLIE0 & CLIE0_C3FIE__BMASK) 44 | #define CLU3_FALLING_EDGE_ENABLED (CLIE0 & CLIE0_C3RIE__BMASK) 45 | 46 | #if EFM8PDL_CLU0_USE_ISR || EFM8PDL_CLU1_USE_ISR || EFM8PDL_CLU2_USE_ISR || EFM8PDL_CLU3_USE_ISR 47 | //----------------------------------------------------------------------------- 48 | // CL0_ISR 49 | //----------------------------------------------------------------------------- 50 | // 51 | // CL0 ISR Content goes here. Remember to clear flag bits: 52 | // CLIF0::C0FIF (CLU0 Falling Edge Interrupt Flag) 53 | // CLIF0::C0RIF (CLU0 Rising Edge Interrupt Flag) 54 | // CLIF0::C1FIF (CLU1 Falling Edge Interrupt Flag) 55 | // CLIF0::C1RIF (CLU1 Rising Edge Interrupt Flag) 56 | // CLIF0::C2FIF (CLU2 Falling Edge Interrupt Flag) 57 | // CLIF0::C2RIF (CLU2 Rising Edge Interrupt Flag) 58 | // CLIF0::C3FIF (CLU3 Falling Edge Interrupt Flag) 59 | // CLIF0::C3RIF (CLU3 Rising Edge Interrupt Flag) 60 | // 61 | //----------------------------------------------------------------------------- 62 | SI_INTERRUPT (CL0_ISR, CL0_IRQn) 63 | { 64 | uint8_t flags = CLIF0; 65 | CLIF0 = 0; 66 | 67 | #if EFM8PDL_CLU0_USE_ISR 68 | if ((flags & CLIF0_C0FIF__BMASK) && CLU0_RISING_EDGE_ENABLED) 69 | { 70 | CLU0_fallingEdgeCb(); 71 | } 72 | 73 | if ((flags & CLIF0_C0RIF__BMASK) && CLU0_FALLING_EDGE_ENABLED) 74 | { 75 | CLU0_risingEdgeCb(); 76 | } 77 | #endif 78 | 79 | #if EFM8PDL_CLU1_USE_ISR 80 | if ((flags & CLIF0_C1FIF__BMASK) && CLU1_RISING_EDGE_ENABLED) 81 | { 82 | CLU1_fallingEdgeCb(); 83 | } 84 | 85 | if ((flags & CLIF0_C1RIF__BMASK) && CLU1_FALLING_EDGE_ENABLED) 86 | { 87 | CLU1_risingEdgeCb(); 88 | } 89 | #endif 90 | 91 | #if EFM8PDL_CLU2_USE_ISR 92 | if ((flags & CLIF0_C2FIF__BMASK) && CLU2_RISING_EDGE_ENABLED) 93 | { 94 | CLU2_fallingEdgeCb(); 95 | } 96 | 97 | if ((flags & CLIF0_C2RIF__BMASK) && CLU2_FALLING_EDGE_ENABLED) 98 | { 99 | CLU2_risingEdgeCb(); 100 | } 101 | #endif 102 | 103 | #if EFM8PDL_CLU3_USE_ISR 104 | if ((flags & CLIF0_C3FIF__BMASK) && CLU3_RISING_EDGE_ENABLED) 105 | { 106 | CLU3_fallingEdgeCb(); 107 | } 108 | 109 | if ((flags & CLIF0_C3RIF__BMASK) && CLU3_FALLING_EDGE_ENABLED) 110 | { 111 | CLU3_risingEdgeCb(); 112 | } 113 | #endif 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EFM8 SDCC makefiles 2 | 3 | Simple makefiles and examples for using the EFM8 series of microcontrollers 4 | with SDCC. 5 | 6 | ## Example projects 7 | 8 | * blink: blinks LEDs on pins P2.2 and P2.3. 9 | 10 | 11 | ## Usage 12 | 13 | ### Building 14 | 15 | Copy one of the example projects, then simply place your source code inside 16 | the `src` directory and add your code to the `C_SRC` variable inside the 17 | makefile. You can then run `make` to build your code. 18 | 19 | To provide multiple variations of a projects for different boards/mcu, you 20 | can use the `boards` directory to make different targets. By default, the 21 | makefile will use the `boards/default` target. If you want to make another 22 | targets create a new directory in the `boards` folder and make a `config.mk` 23 | file inside of it with the settings for that build. 24 | 25 | To build different board targets, you can call make and set the `BORADS` 26 | variable: 27 | 28 | ```sh 29 | make BOARD=default 30 | ``` 31 | 32 | ### Programming 33 | 34 | To program you can use Silicon Labs USB debug adapter. You can buy this from 35 | digikey/mouser for about 35$, or from ebay/aliexpress for about 10$. 36 | 37 | To use the command line tools to flash hex files, you will first need to [download 38 | Simplicity Studio](https://www.silabs.com/products/development-tools/software/simplicity-studio). Then from simplicity studio install the 8051 toolchain and flashing devices. 39 | Once installed, you will need to provide the makefiles with the path where you 40 | installed Simplicity Studio, for example: 41 | 42 | ```makefile 43 | # Inside makefile 44 | SIMPLICITY_STUDIO_PATH = $(HOME)/local/simplicity_studio/SimplicityStudio_v4 45 | ``` 46 | 47 | You should then be able to use the targets provided by the makefiles to 48 | flash from the command line. First to list the connected devices use the 49 | `program-list` target: 50 | 51 | ```sh 52 | $ make program-list 53 | deviceCount = 1 54 | device (EC3005481E8) { 55 | adapterLabel = USB Debug Adapter 56 | SerialNo = EC3005481E8 57 | targetInterface = c2 58 | Name = EFM8UB20F32G-QFP32 59 | Type = MCU 60 | Family = 8051 61 | HardwareID = 0x28 62 | DerivativeID = 0x64 63 | HardwareRev = 0x0 64 | DerivativeRev = 0x6 65 | Unsupported = 0 66 | Indeterminate = 0 67 | Connected = 0 68 | Locked = 0 69 | } 70 | ``` 71 | 72 | From this listing you can see the serial numbers of the connected devices, 73 | `EC3005481E8` in this example. Once you know the serial number, you can use 74 | the `program-efm8` target to flash it: 75 | 76 | ```sh 77 | make program-efm8 SERIAL_NUM=EC3005481E8 78 | ``` 79 | 80 | ## Documentation 81 | 82 | ### Datasheet 83 | 84 | * [C8051F38x](https://www.silabs.com/documents/public/data-sheets/C8051F38x.pdf) 85 | * [efm8ub1](https://www.silabs.com/documents/public/data-sheets/efm8ub1-datasheet.pdf) 86 | * [efm8ub2](https://www.silabs.com/documents/public/data-sheets/efm8ub2-datasheet.pdf) 87 | * [efm8ub3](https://www.silabs.com/documents/public/data-sheets/efm8ub3-datasheet.pdf) 88 | 89 | ### Reference manuals 90 | 91 | * [efm8ub1](https://www.silabs.com/documents/public/reference-manuals/EFM8UB1-RM.pdf) 92 | * [efm8ub2](https://www.silabs.com/documents/public/reference-manuals/EFM8UB2-RM.pdf) 93 | * [efm8ub3](https://www.silabs.com/documents/public/reference-manuals/efm8ub3-reference-manual.pdf) 94 | 95 | ## Dev tools 96 | 97 | * https://www.silabs.com/products/development-tools/software/simplicity-studio 98 | 99 | ## Programmer code for C2 interface (arduino based): 100 | 101 | * https://github.com/x893/C2.Flash 102 | * https://github.com/lhartmann/c2_prog_wifi/blob/master/arduino_libs/c2_prog/c2.cpp 103 | * https://www.silabs.com/documents/public/application-notes/AN127.pdf 104 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB1/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t i; 41 | 42 | // Wait for previous transfer to complete 43 | while (TransferState != ST_IDLE); 44 | 45 | // Start new transfer 46 | TransferState = ST_CS_SETUP; 47 | TransferSize = size; 48 | 49 | for (i = 0; i < size; i++) 50 | { 51 | TxBuffer[i] = buffer[i]; 52 | } 53 | 54 | // CS setup time 55 | // Timer 2 overflows at end of setup time 56 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 57 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 58 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 59 | } 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // Interrupt Service Handlers 63 | ///////////////////////////////////////////////////////////////////////////// 64 | 65 | void SPI0_transferCompleteCb(void) 66 | { 67 | // CS hold time 68 | TransferState = ST_CS_HOLD; 69 | 70 | // CS hold time 71 | // Timer 2 overflows at end of hold time 72 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 73 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 74 | } 75 | 76 | //----------------------------------------------------------------------------- 77 | // TIMER2_ISR 78 | //----------------------------------------------------------------------------- 79 | // 80 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 81 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 82 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 83 | // 84 | //----------------------------------------------------------------------------- 85 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 86 | { 87 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 88 | 89 | // Stop timer 90 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 91 | 92 | // CS setup complete 93 | if (TransferState == ST_CS_SETUP) 94 | { 95 | TransferState = ST_TX; 96 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 97 | } 98 | // CS hold complete 99 | else if (TransferState == ST_CS_HOLD) 100 | { 101 | // Deassert CS 102 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 103 | 104 | // Transfer complete 105 | TransferState = ST_IDLE; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB2/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_1.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI1_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t i; 41 | 42 | // Wait for previous transfer to complete 43 | while (TransferState != ST_IDLE); 44 | 45 | // Start new transfer 46 | TransferState = ST_CS_SETUP; 47 | TransferSize = size; 48 | 49 | for (i = 0; i < size; i++) 50 | { 51 | TxBuffer[i] = buffer[i]; 52 | } 53 | 54 | // CS setup time 55 | // Timer 2 overflows at end of setup time 56 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 57 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 58 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 59 | } 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // Interrupt Service Handlers 63 | ///////////////////////////////////////////////////////////////////////////// 64 | 65 | void SPI1_transferCompleteCb(void) 66 | { 67 | // CS hold time 68 | TransferState = ST_CS_HOLD; 69 | 70 | // CS hold time 71 | // Timer 2 overflows at end of hold time 72 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 73 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 74 | } 75 | 76 | //----------------------------------------------------------------------------- 77 | // TIMER2_ISR 78 | //----------------------------------------------------------------------------- 79 | // 80 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 81 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 82 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 83 | // 84 | //----------------------------------------------------------------------------- 85 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 86 | { 87 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 88 | 89 | // Stop timer 90 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 91 | 92 | // CS setup complete 93 | if (TransferState == ST_CS_SETUP) 94 | { 95 | TransferState = ST_TX; 96 | SPI1_transfer(TxBuffer, NULL, SPI1_TRANSFER_TX, TransferSize); 97 | } 98 | // CS hold complete 99 | else if (TransferState == ST_CS_HOLD) 100 | { 101 | // Deassert CS 102 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 103 | 104 | // Transfer complete 105 | TransferState = ST_IDLE; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/peripheral_driver/src/pwr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "pwr.h" 8 | 9 | #if (EFM8PDL_PWR_AUTO_PAGE == 1) 10 | #define SAVE_SFRPAGE uint8_t save_sfrpage = SFRPAGE 11 | #define RESTORE_SFRPAGE SFRPAGE = save_sfrpage 12 | #else 13 | #define SAVE_SFRPAGE 14 | #define RESTORE_SFRPAGE 15 | #endif 16 | 17 | void PWR_enterIdle(void) 18 | { 19 | SAVE_SFRPAGE; 20 | SFRPAGE = 0; 21 | 22 | // Set the IDLE bit followed by a 3-cycle dummy instruction to ensure the 23 | // CPU wakes under all conditions (see ref manual) 24 | PCON0 |= PCON0_IDLE__IDLE; 25 | PCON0 = PCON0; 26 | 27 | RESTORE_SFRPAGE; 28 | } 29 | 30 | #if (EFM8PDL_PWR_USE_STOP == 1) 31 | void PWR_enterStop(void) 32 | { 33 | // No need to service interrupts or save the SFRPAGE since the device 34 | // will be stopped 35 | IE_EA = 0; 36 | SFRPAGE = 0; 37 | 38 | // Clock source must be HFOSC0 for lowest power (see ref manual) 39 | // Enable HFOSC0 then source the system clock from it 40 | HFOCN |= HFOCN_HFO0EN__ENABLED; 41 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 42 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 43 | 44 | // Set the STOP bit 45 | PCON0 |= PCON0_STOP__BMASK; 46 | 47 | // NOTE: Reset is required to exit stop mode. Program execution 48 | // will not continue to this point. 49 | } 50 | #endif // EFM8PDL_PWR_USE_STOP 51 | 52 | void PWR_enterSuspend(void) 53 | { 54 | uint8_t save_ie, save_clksel; 55 | SAVE_SFRPAGE; 56 | SFRPAGE = 0; 57 | 58 | // Disable interrupts until the system is awake and restored 59 | save_ie = IE; 60 | IE_EA = 0; 61 | 62 | // System clock must be HFOSC0 (see ref manual) 63 | // Set the system clock to HFOSC0 / 1 64 | save_clksel = CLKSEL; 65 | HFOCN |= HFOCN_HFO0EN__ENABLED; 66 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 67 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 68 | 69 | // Enter suspend mode 70 | PCON1 |= PCON1_SUSPEND__SUSPEND; 71 | 72 | // Next restore the system clock source and divider 73 | CLKSEL = save_clksel; 74 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 75 | 76 | // Finally restore the interrupt enable 77 | IE = save_ie; 78 | RESTORE_SFRPAGE; 79 | } 80 | 81 | void PWR_enterSnooze(void) 82 | { 83 | uint8_t save_ie, save_clksel; 84 | SAVE_SFRPAGE; 85 | SFRPAGE = 0; 86 | 87 | // Disable interrupts until the system is awake and restored 88 | save_ie = IE; 89 | IE_EA = 0; 90 | 91 | // System clock must be HFOSC0 (see ref manual) 92 | // Set the system clock to HFOSC0 / 1 93 | save_clksel = CLKSEL; 94 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 95 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 96 | 97 | // Enter suspend mode 98 | PCON1 |= PCON1_SNOOZE__SNOOZE; 99 | 100 | // Next restore the system clock source and divider 101 | CLKSEL = save_clksel; 102 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 103 | 104 | // Finally restore the interrupt enable 105 | IE = save_ie; 106 | RESTORE_SFRPAGE; 107 | } 108 | 109 | void PWR_enterShutdown(void) 110 | { 111 | // No need to service interrupts or save the SFRPAGE since the device 112 | // will be stopped 113 | IE_EA = 0; 114 | SFRPAGE = 0; 115 | 116 | // Set the STOPCF bit to shutdown regulator 117 | REG0CN |= REG0CN_STOPCF__SHUTDOWN; 118 | 119 | // Set the STOP bit 120 | PCON0 |= PCON0_STOP__BMASK; 121 | 122 | // NOTE: Reset is required to exit stop mode. Program execution 123 | // will not continue to this point. 124 | } 125 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/peripheral_driver/src/pwr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "pwr.h" 8 | 9 | #if (EFM8PDL_PWR_AUTO_PAGE == 1) 10 | #define SAVE_SFRPAGE uint8_t save_sfrpage = SFRPAGE 11 | #define RESTORE_SFRPAGE SFRPAGE = save_sfrpage 12 | #else 13 | #define SAVE_SFRPAGE 14 | #define RESTORE_SFRPAGE 15 | #endif 16 | 17 | void PWR_enterIdle(void) 18 | { 19 | SAVE_SFRPAGE; 20 | SFRPAGE = 0; 21 | 22 | // Set the IDLE bit followed by a 3-cycle dummy instruction to ensure the 23 | // CPU wakes under all conditions (see ref manual) 24 | PCON0 |= PCON0_IDLE__IDLE; 25 | PCON0 = PCON0; 26 | 27 | RESTORE_SFRPAGE; 28 | } 29 | 30 | #if (EFM8PDL_PWR_USE_STOP == 1) 31 | void PWR_enterStop(void) 32 | { 33 | // No need to service interrupts or save the SFRPAGE since the device 34 | // will be stopped 35 | IE_EA = 0; 36 | SFRPAGE = 0; 37 | 38 | // Clock source must be HFOSC0 for lowest power (see ref manual) 39 | // Enable HFOSC0 then source the system clock from it 40 | HFOCN |= HFOCN_HFO0EN__ENABLED; 41 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 42 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 43 | 44 | // Set the STOP bit 45 | PCON0 |= PCON0_STOP__BMASK; 46 | 47 | // NOTE: Reset is required to exit stop mode. Program execution 48 | // will not continue to this point. 49 | } 50 | #endif // EFM8PDL_PWR_USE_STOP 51 | 52 | void PWR_enterSuspend(void) 53 | { 54 | uint8_t save_ie, save_clksel; 55 | SAVE_SFRPAGE; 56 | SFRPAGE = 0; 57 | 58 | // Disable interrupts until the system is awake and restored 59 | save_ie = IE; 60 | IE_EA = 0; 61 | 62 | // System clock must be HFOSC0 (see ref manual) 63 | // Set the system clock to HFOSC0 / 1 64 | save_clksel = CLKSEL; 65 | HFOCN |= HFOCN_HFO0EN__ENABLED; 66 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 67 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 68 | 69 | // Enter suspend mode 70 | PCON1 |= PCON1_SUSPEND__SUSPEND; 71 | 72 | // Next restore the system clock source and divider 73 | CLKSEL = save_clksel; 74 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 75 | 76 | // Finally restore the interrupt enable 77 | IE = save_ie; 78 | RESTORE_SFRPAGE; 79 | } 80 | 81 | void PWR_enterSnooze(void) 82 | { 83 | uint8_t save_ie, save_clksel; 84 | SAVE_SFRPAGE; 85 | SFRPAGE = 0; 86 | 87 | // Disable interrupts until the system is awake and restored 88 | save_ie = IE; 89 | IE_EA = 0; 90 | 91 | // System clock must be HFOSC0 (see ref manual) 92 | // Set the system clock to HFOSC0 / 1 93 | save_clksel = CLKSEL; 94 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 95 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 96 | 97 | // Enter suspend mode 98 | PCON1 |= PCON1_SNOOZE__SNOOZE; 99 | 100 | // Next restore the system clock source and divider 101 | CLKSEL = save_clksel; 102 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 103 | 104 | // Finally restore the interrupt enable 105 | IE = save_ie; 106 | RESTORE_SFRPAGE; 107 | } 108 | 109 | void PWR_enterShutdown(void) 110 | { 111 | // No need to service interrupts or save the SFRPAGE since the device 112 | // will be stopped 113 | IE_EA = 0; 114 | SFRPAGE = 0; 115 | 116 | // Set the STOPCF bit to shutdown regulator 117 | REG0CN |= REG0CN_STOPCF__SHUTDOWN; 118 | 119 | // Set the STOP bit 120 | PCON0 |= PCON0_STOP__BMASK; 121 | 122 | // NOTE: Reset is required to exit stop mode. Program execution 123 | // will not continue to this point. 124 | } 125 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB3/peripheral_driver/src/pwr.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "pwr.h" 8 | 9 | #if (EFM8PDL_PWR_AUTO_PAGE == 1) 10 | #define SAVE_SFRPAGE uint8_t save_sfrpage = SFRPAGE 11 | #define RESTORE_SFRPAGE SFRPAGE = save_sfrpage 12 | #else 13 | #define SAVE_SFRPAGE 14 | #define RESTORE_SFRPAGE 15 | #endif 16 | 17 | void PWR_enterIdle(void) 18 | { 19 | SAVE_SFRPAGE; 20 | SFRPAGE = 0; 21 | 22 | // Set the IDLE bit followed by a 3-cycle dummy instruction to ensure the 23 | // CPU wakes under all conditions (see ref manual) 24 | PCON0 |= PCON0_IDLE__IDLE; 25 | PCON0 = PCON0; 26 | 27 | RESTORE_SFRPAGE; 28 | } 29 | 30 | #if (EFM8PDL_PWR_USE_STOP == 1) 31 | void PWR_enterStop(void) 32 | { 33 | // No need to service interrupts or save the SFRPAGE since the device 34 | // will be stopped 35 | IE_EA = 0; 36 | SFRPAGE = 0; 37 | 38 | // Clock source must be HFOSC0 for lowest power (see ref manual) 39 | // Enable HFOSC0 then source the system clock from it 40 | HFOCN |= HFOCN_HFO0EN__ENABLED; 41 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 42 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 43 | 44 | // Set the STOP bit 45 | PCON0 |= PCON0_STOP__BMASK; 46 | 47 | // NOTE: Reset is required to exit stop mode. Program execution 48 | // will not continue to this point. 49 | } 50 | #endif // EFM8PDL_PWR_USE_STOP 51 | 52 | void PWR_enterSuspend(void) 53 | { 54 | uint8_t save_ie, save_clksel; 55 | SAVE_SFRPAGE; 56 | SFRPAGE = 0; 57 | 58 | // Disable interrupts until the system is awake and restored 59 | save_ie = IE; 60 | IE_EA = 0; 61 | 62 | // System clock must be HFOSC0 (see ref manual) 63 | // Set the system clock to HFOSC0 / 1 64 | save_clksel = CLKSEL; 65 | HFOCN |= HFOCN_HFO0EN__ENABLED; 66 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 67 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 68 | 69 | // Enter suspend mode 70 | PCON1 |= PCON1_SUSPEND__SUSPEND; 71 | 72 | // Next restore the system clock source and divider 73 | CLKSEL = save_clksel; 74 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 75 | 76 | // Finally restore the interrupt enable 77 | IE = save_ie; 78 | RESTORE_SFRPAGE; 79 | } 80 | 81 | void PWR_enterSnooze(void) 82 | { 83 | uint8_t save_ie, save_clksel; 84 | SAVE_SFRPAGE; 85 | SFRPAGE = 0; 86 | 87 | // Disable interrupts until the system is awake and restored 88 | save_ie = IE; 89 | IE_EA = 0; 90 | 91 | // System clock must be HFOSC0 (see ref manual) 92 | // Set the system clock to HFOSC0 / 1 93 | save_clksel = CLKSEL; 94 | CLKSEL = CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0; 95 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 96 | 97 | // Enter suspend mode 98 | PCON1 |= PCON1_SNOOZE__SNOOZE; 99 | 100 | // Next restore the system clock source and divider 101 | CLKSEL = save_clksel; 102 | while((CLKSEL & CLKSEL_DIVRDY__BMASK) == 0); 103 | 104 | // Finally restore the interrupt enable 105 | IE = save_ie; 106 | RESTORE_SFRPAGE; 107 | } 108 | 109 | void PWR_enterShutdown(void) 110 | { 111 | // No need to service interrupts or save the SFRPAGE since the device 112 | // will be stopped 113 | IE_EA = 0; 114 | SFRPAGE = 0; 115 | 116 | // Set the STOPCF bit to shutdown regulator 117 | REG0CN |= REG0CN_STOPCF__SHUTDOWN; 118 | 119 | // Set the STOP bit 120 | PCON0 |= PCON0_STOP__BMASK; 121 | 122 | // NOTE: Reset is required to exit stop mode. Program execution 123 | // will not continue to this point. 124 | } 125 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB2/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8SB1/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB1/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8UB2/bsp/efm8_memory_lcd/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/bsp/efm8_memory_lcd/source/spi.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // Spi.c 8 | ///////////////////////////////////////////////////////////////////////////// 9 | 10 | // SPI FIFO Format 11 | // --------------- 12 | // 13 | // All SPI transfers are pushed to the TX FIFO with the transfer size in 14 | // bytes followed by the data to transmit. 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // Includes 18 | ///////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "bsp.h" 21 | #include "spi.h" 22 | #include "spi_0.h" 23 | #include 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // Globals 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 29 | static SI_SEGMENT_VARIABLE(TxBuffer[SPI_BUF_SIZE], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); 30 | 31 | static volatile uint8_t TransferState = ST_IDLE; 32 | static volatile uint8_t TransferSize = 0; 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // Functions 36 | ///////////////////////////////////////////////////////////////////////////// 37 | 38 | void SPI_StartTransfer(SI_VARIABLE_SEGMENT_POINTER(buffer, uint8_t, SI_SEG_GENERIC), uint8_t size) 39 | { 40 | uint8_t sfrPageSave; 41 | uint8_t i; 42 | 43 | // Wait for previous transfer to complete 44 | while (TransferState != ST_IDLE); 45 | 46 | // Start new transfer 47 | TransferState = ST_CS_SETUP; 48 | TransferSize = size; 49 | 50 | for (i = 0; i < size; i++) 51 | { 52 | TxBuffer[i] = buffer[i]; 53 | } 54 | 55 | sfrPageSave = SFRPAGE; 56 | SFRPAGE = LEGACY_PAGE; 57 | 58 | // CS setup time 59 | // Timer 2 overflows at end of setup time 60 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_SETUP_US); 61 | BSP_DISP_CS = SPI_CS_ASSERT_LVL; 62 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 63 | 64 | SFRPAGE = sfrPageSave; 65 | } 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | // Interrupt Service Handlers 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | void SPI0_transferCompleteCb(void) 72 | { 73 | uint8_t sfrPageSave; 74 | 75 | // CS hold time 76 | TransferState = ST_CS_HOLD; 77 | 78 | sfrPageSave = SFRPAGE; 79 | SFRPAGE = LEGACY_PAGE; 80 | 81 | // CS hold time 82 | // Timer 2 overflows at end of hold time 83 | TMR2 = (uint16_t)-(DELAY_TIMER_FREQ / 1000000 * SPI_CS_HOLD_US); 84 | TMR2CN0 |= TMR2CN0_TR2__BMASK; 85 | 86 | SFRPAGE = sfrPageSave; 87 | } 88 | 89 | //----------------------------------------------------------------------------- 90 | // TIMER2_ISR 91 | //----------------------------------------------------------------------------- 92 | // 93 | // TIMER2 ISR Content goes here. Remember to clear flag bits: 94 | // TMR2CN::TF2H (Timer # High Byte Overflow Flag) 95 | // TMR2CN::TF2L (Timer # Low Byte Overflow Flag) 96 | // 97 | //----------------------------------------------------------------------------- 98 | SI_INTERRUPT (TIMER2_ISR, TIMER2_IRQn) 99 | { 100 | TMR2CN0 &= ~TMR2CN0_TF2H__BMASK; 101 | 102 | // Stop timer 103 | TMR2CN0 &= ~TMR2CN0_TR2__BMASK; 104 | 105 | // CS setup complete 106 | if (TransferState == ST_CS_SETUP) 107 | { 108 | TransferState = ST_TX; 109 | SPI0_transfer(TxBuffer, NULL, SPI0_TRANSFER_TX, TransferSize); 110 | } 111 | // CS hold complete 112 | else if (TransferState == ST_CS_HOLD) 113 | { 114 | // Deassert CS 115 | BSP_DISP_CS = SPI_CS_DEASSERT_LVL; 116 | 117 | // Transfer complete 118 | TransferState = ST_IDLE; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB1/peripheral_driver/src/adc_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2016 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "adc_0.h" 8 | #include "assert.h" 9 | 10 | #define ADC0_enableTempSensor() REF0CN |= 0x04 11 | #define ADC0_disableTempSensor() REF0CN &= 0xFB 12 | 13 | #if EFM8PDL_ADC0_USE_INIT == 1 14 | #define MAX_SARCLK 12500000UL 15 | #define MAX_SYSCLK 25000000UL 16 | 17 | void ADC0_init(ADC0_ConversionStart_t convStart, 18 | ADC0_Resolution_t resolution, 19 | uint32_t sysclk) 20 | { 21 | uint8_t divider; 22 | 23 | // Sysclk cannot be greater than the maximum 24 | SLAB_ASSERT(sysclk <= MAX_SYSCLK); 25 | 26 | // calculate SAR clock divider 27 | divider = 0; 28 | while(sysclk > MAX_SARCLK * (divider + 1)) 29 | { 30 | divider++; 31 | } 32 | 33 | if(resolution == ADC0_RESOLUTION_8_BIT) 34 | { 35 | ADC0CF = resolution | ADC0CF_ADGN__GAIN_0P5 | (divider << ADC0CF_ADSC__SHIFT); 36 | ADC0AC = ADC0AC_ADRPT__ACC_1 | ADC0AC_ADSJST__RIGHT_NO_SHIFT; 37 | ADC0CN0 = convStart; 38 | } 39 | else 40 | { 41 | ADC0CF = ADC0CF_ADGN__GAIN_0P5 | (divider << ADC0CF_ADSC__SHIFT); 42 | if(resolution == ADC0_RESOLUTION_10_BIT) 43 | { 44 | ADC0AC = resolution | ADC0AC_ADRPT__ACC_1 | ADC0AC_ADSJST__RIGHT_NO_SHIFT; 45 | ADC0CN0 = convStart; 46 | } 47 | else // resolution == ADC0_RESOLUTION_12_BIT 48 | { 49 | ADC0AC = resolution | ADC0AC_ADRPT__ACC_4 | ADC0AC_ADSJST__RIGHT_NO_SHIFT; 50 | ADC0CN0 = convStart | ADC0CN0_ADBMEN__BURST_ENABLED; 51 | } 52 | } 53 | 54 | // Enable ADC 55 | ADC0CN0_ADEN = 1; 56 | } 57 | #endif //EFM8PDL_ADC0_USE_INIT 58 | 59 | uint8_t ADC0_getIntFlags() 60 | { 61 | uint8_t val; 62 | val = ADC0CN0 & (ADC0_CONVERSION_COMPLETE_IF | ADC0_WINDOW_COMPARE_IF); 63 | return val; 64 | } 65 | 66 | void ADC0_clearIntFlags(uint8_t flags) 67 | { 68 | 69 | // Must pass one of the valid flags 70 | SLAB_ASSERT(flags & (ADC0_CONVERSION_COMPLETE_IF | ADC0_WINDOW_COMPARE_IF)); 71 | 72 | ADC0CN0 &= ~(flags & (ADC0_CONVERSION_COMPLETE_IF | ADC0_WINDOW_COMPARE_IF)); 73 | } 74 | 75 | void ADC0_enableInt(uint8_t flags, bool enable) 76 | { 77 | uint8_t en; 78 | 79 | // Must pass one of the valid flags 80 | SLAB_ASSERT(flags & (ADC0_CONVERSION_COMPLETE_IF | ADC0_WINDOW_COMPARE_IF)); 81 | 82 | en = (uint8_t) enable; 83 | 84 | if (flags & ADC0_CONVERSION_COMPLETE_IF) 85 | { 86 | EIE1 &= ~EIE1_EADC0__BMASK; 87 | EIE1 |= en << EIE1_EADC0__SHIFT; 88 | } 89 | 90 | if (flags & ADC0_WINDOW_COMPARE_IF) 91 | { 92 | EIE1 &= ~EIE1_EWADC0__BMASK; 93 | EIE1 |= en << EIE1_EWADC0__SHIFT; 94 | } 95 | } 96 | 97 | 98 | void ADC0_enable(void) 99 | { 100 | ADC0CN0_ADEN = 1; 101 | } 102 | 103 | void ADC0_disable(void) 104 | { 105 | ADC0CN0_ADEN = 0; 106 | } 107 | 108 | void ADC0_setPositiveInput(ADC0_PositiveInput_t input) 109 | { 110 | 111 | // Turn on the temp sensor if it is the input 112 | if (input == ADC0_POSITIVE_INPUT_TEMP) 113 | { 114 | ADC0_enableTempSensor(); 115 | } 116 | else 117 | { 118 | ADC0_disableTempSensor(); 119 | } 120 | 121 | ADC0MX = input; 122 | } 123 | 124 | void ADC0_startConversion(void) 125 | { 126 | uint8_t ADCM_save; 127 | 128 | // Save the conversion source and set to ADBUSY 129 | ADCM_save = ADC0CN0 & ADC0CN0_ADCM__FMASK; 130 | ADC0CN0 = (ADC0CN0 & ~ADC0CN0_ADCM__FMASK) | ADC0CN0_ADCM__ADBUSY; 131 | 132 | // Clear the conversion complete flag 133 | ADC0CN0_ADINT = 0; 134 | 135 | // Start a conversion by setting ADBUSY 136 | ADC0CN0_ADBUSY = 1; 137 | 138 | // Restore the conversion source 139 | ADC0CN0 |= ADCM_save; 140 | } 141 | 142 | bool ADC0_isConversionComplete(void) 143 | { 144 | bool conversionComplete; 145 | conversionComplete = ADC0CN0_ADINT; 146 | return conversionComplete; 147 | } 148 | 149 | uint16_t ADC0_getResult(void) 150 | { 151 | uint16_t result; 152 | result = ADC0; 153 | return result; 154 | } 155 | 156 | void ADC0_setWindowCompare(uint16_t lessThan, uint16_t greaterThan) 157 | { 158 | ADC0LT = lessThan; 159 | ADC0GT = greaterThan; 160 | } 161 | 162 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/clu_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_0.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU0_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU0_init(CLU0_InputA_t inputA, 33 | CLU0_InputB_t inputB, 34 | CLU0_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU0MX = inputA | inputB; 40 | CLU0CF = (CLU0CF & ~CLU0CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C0EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU0_initFlipflop(CLU0_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU0CF = (CLU0CF & ~CLU0CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU0CF_CLKINV__SHIFT); 53 | CLU0CF = (CLU0CF & ~CLU0CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU0_setOutputFunction(CLU0_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU0FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU0_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU0_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU0_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU0_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C0RIE__BMASK) | (en << CLIE0_C0RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU0_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C0FIE__BMASK) | (en << CLIE0_C0FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU0_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C0EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU0_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C0EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU0_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU0CF |= CLU0CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU0_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU0CF &= ~CLU0CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU0_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C0OUT__BMASK) == CLOUT0_C0OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/clu_1.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_1.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU1_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU1_init(CLU1_InputA_t inputA, 33 | CLU1_InputB_t inputB, 34 | CLU1_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU1MX = inputA | inputB; 40 | CLU1CF = (CLU1CF & ~CLU1CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C1EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU1_initFlipflop(CLU1_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU1CF = (CLU1CF & ~CLU1CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU1CF_CLKINV__SHIFT); 53 | CLU1CF = (CLU1CF & ~CLU1CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU1_setOutputFunction(CLU1_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU1FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU1_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU1_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU1_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU1_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C1RIE__BMASK) | (en << CLIE0_C1RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU1_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C1FIE__BMASK) | (en << CLIE0_C1FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU1_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C1EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU1_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C1EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU1_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU1CF |= CLU1CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU1_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU1CF &= ~CLU1CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU1_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C1OUT__BMASK) == CLOUT0_C1OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/clu_2.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_2.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU2_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU2_init(CLU2_InputA_t inputA, 33 | CLU2_InputB_t inputB, 34 | CLU2_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU2MX = inputA | inputB; 40 | CLU2CF = (CLU2CF & ~CLU2CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C2EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU2_initFlipflop(CLU2_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU2CF = (CLU2CF & ~CLU2CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU2CF_CLKINV__SHIFT); 53 | CLU2CF = (CLU2CF & ~CLU2CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU2_setOutputFunction(CLU2_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU2FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU2_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU2_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU2_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU2_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C2RIE__BMASK) | (en << CLIE0_C2RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU2_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C2FIE__BMASK) | (en << CLIE0_C2FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU2_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C2EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU2_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C2EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU2_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU2CF |= CLU2CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU2_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU2CF &= ~CLU2CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU2_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C2OUT__BMASK) == CLOUT0_C2OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8BB3/peripheral_driver/src/clu_3.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_3.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU3_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU3_init(CLU3_InputA_t inputA, 33 | CLU3_InputB_t inputB, 34 | CLU3_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU3MX = inputA | inputB; 40 | CLU3CF = (CLU3CF & ~CLU3CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C3EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU3_initFlipflop(CLU3_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU3CF = (CLU3CF & ~CLU3CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU3CF_CLKINV__SHIFT); 53 | CLU3CF = (CLU3CF & ~CLU3CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU3_setOutputFunction(CLU3_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU3FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU3_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU3_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU3_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU3_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C3RIE__BMASK) | (en << CLIE0_C3RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU3_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C3FIE__BMASK) | (en << CLIE0_C3FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU3_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C3EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU3_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C3EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU3_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU3CF |= CLU3CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU3_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU3CF &= ~CLU3CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU3_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C3OUT__BMASK) == CLOUT0_C3OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/clu_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_0.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU0_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU0_init(CLU0_InputA_t inputA, 33 | CLU0_InputB_t inputB, 34 | CLU0_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU0MX = inputA | inputB; 40 | CLU0CF = (CLU0CF & ~CLU0CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C0EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU0_initFlipflop(CLU0_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU0CF = (CLU0CF & ~CLU0CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU0CF_CLKINV__SHIFT); 53 | CLU0CF = (CLU0CF & ~CLU0CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU0_setOutputFunction(CLU0_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU0FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU0_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU0_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU0_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU0_RISING_EDGE_IF | CLU0_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU0_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C0RIE__BMASK) | (en << CLIE0_C0RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU0_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C0FIE__BMASK) | (en << CLIE0_C0FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU0_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C0EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU0_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C0EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU0_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU0CF |= CLU0CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU0_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU0CF &= ~CLU0CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU0_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C0OUT__BMASK) == CLOUT0_C0OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/clu_1.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_1.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU1_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU1_init(CLU1_InputA_t inputA, 33 | CLU1_InputB_t inputB, 34 | CLU1_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU1MX = inputA | inputB; 40 | CLU1CF = (CLU1CF & ~CLU1CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C1EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU1_initFlipflop(CLU1_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU1CF = (CLU1CF & ~CLU1CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU1CF_CLKINV__SHIFT); 53 | CLU1CF = (CLU1CF & ~CLU1CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU1_setOutputFunction(CLU1_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU1FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU1_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU1_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU1_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU1_RISING_EDGE_IF | CLU1_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU1_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C1RIE__BMASK) | (en << CLIE0_C1RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU1_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C1FIE__BMASK) | (en << CLIE0_C1FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU1_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C1EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU1_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C1EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU1_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU1CF |= CLU1CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU1_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU1CF &= ~CLU1CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU1_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C1OUT__BMASK) == CLOUT0_C1OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/clu_2.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_2.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU2_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU2_init(CLU2_InputA_t inputA, 33 | CLU2_InputB_t inputB, 34 | CLU2_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU2MX = inputA | inputB; 40 | CLU2CF = (CLU2CF & ~CLU2CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C2EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU2_initFlipflop(CLU2_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU2CF = (CLU2CF & ~CLU2CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU2CF_CLKINV__SHIFT); 53 | CLU2CF = (CLU2CF & ~CLU2CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU2_setOutputFunction(CLU2_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU2FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU2_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU2_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU2_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU2_RISING_EDGE_IF | CLU2_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU2_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C2RIE__BMASK) | (en << CLIE0_C2RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU2_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C2FIE__BMASK) | (en << CLIE0_C2FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU2_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C2EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU2_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C2EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU2_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU2CF |= CLU2CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU2_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU2CF &= ~CLU2CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU2_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C2OUT__BMASK) == CLOUT0_C2OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | -------------------------------------------------------------------------------- /efm8/mcu/EFM8LB1/peripheral_driver/src/clu_3.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "clu_3.h" 8 | #include "assert.h" 9 | 10 | #if EFM8PDL_CLU3_AUTO_PAGE == 1 11 | // declare variable needed for autopage enter/exit 12 | #define DECL_PAGE uint8_t savedPage 13 | // enter autopage section 14 | #define SET_PAGE(p) do \ 15 | { \ 16 | savedPage = SFRPAGE; /* save current SFR page */ \ 17 | SFRPAGE = (p); /* set SFR page */ \ 18 | } while(0) 19 | // exit autopage section 20 | #define RESTORE_PAGE do \ 21 | { \ 22 | SFRPAGE = savedPage; /* restore saved SFR page */ \ 23 | } while(0) 24 | #else 25 | #define DECL_PAGE 26 | #define SET_PAGE(p) 27 | #define RESTORE_PAGE 28 | #endif 29 | 30 | #define SFRPAGE_CLU (0x20) 31 | 32 | void CLU3_init(CLU3_InputA_t inputA, 33 | CLU3_InputB_t inputB, 34 | CLU3_OutputMode_t mode) 35 | { 36 | DECL_PAGE; 37 | SET_PAGE(SFRPAGE_CLU); 38 | 39 | CLU3MX = inputA | inputB; 40 | CLU3CF = (CLU3CF & ~CLU3CF_OUTSEL__BMASK) | mode; 41 | 42 | CLEN0 |= CLEN0_C3EN__ENABLE; 43 | 44 | RESTORE_PAGE; 45 | } 46 | 47 | void CLU3_initFlipflop(CLU3_FlipflopClock_t clock, bool clockInvert) 48 | { 49 | DECL_PAGE; 50 | SET_PAGE(SFRPAGE_CLU); 51 | 52 | CLU3CF = (CLU3CF & ~CLU3CF_CLKINV__BMASK) | ((uint8_t)clockInvert << CLU3CF_CLKINV__SHIFT); 53 | CLU3CF = (CLU3CF & ~CLU3CF_CLKSEL__FMASK) | clock; 54 | 55 | RESTORE_PAGE; 56 | } 57 | 58 | void CLU3_setOutputFunction(CLU3_Function_t function) 59 | { 60 | DECL_PAGE; 61 | SET_PAGE(SFRPAGE_CLU); 62 | CLU3FN = (uint8_t) function; 63 | RESTORE_PAGE; 64 | } 65 | 66 | uint8_t CLU3_getIntFlags(void) 67 | { 68 | uint8_t flags; 69 | DECL_PAGE; 70 | SET_PAGE(SFRPAGE_CLU); 71 | 72 | flags = CLIF0 & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF); 73 | 74 | RESTORE_PAGE; 75 | return flags; 76 | } 77 | 78 | void CLU3_clearIntFlags(uint8_t flags) 79 | { 80 | DECL_PAGE; 81 | SET_PAGE(SFRPAGE_CLU); 82 | 83 | // Must pass one of the valid flags 84 | SLAB_ASSERT(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 85 | 86 | CLIF0 &= ~(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 87 | RESTORE_PAGE; 88 | } 89 | 90 | void CLU3_enableInt(uint8_t flags, bool enable) 91 | { 92 | uint8_t en; 93 | DECL_PAGE; 94 | SET_PAGE(SFRPAGE_CLU); 95 | en = (uint8_t) enable; 96 | 97 | // Must pass one of the valid flags 98 | SLAB_ASSERT(flags & (CLU3_RISING_EDGE_IF | CLU3_FALLING_EDGE_IF)); 99 | 100 | if(flags & CLU3_RISING_EDGE_IF) 101 | { 102 | CLIE0 = (CLIE0 & ~CLIE0_C3RIE__BMASK) | (en << CLIE0_C3RIE__SHIFT); 103 | } 104 | 105 | if(flags & CLU3_FALLING_EDGE_IF) 106 | { 107 | CLIE0 = (CLIE0 & ~CLIE0_C3FIE__BMASK) | (en << CLIE0_C3FIE__SHIFT); 108 | } 109 | 110 | RESTORE_PAGE; 111 | } 112 | 113 | void CLU3_enable(void) 114 | { 115 | DECL_PAGE; 116 | SET_PAGE(SFRPAGE_CLU); 117 | CLEN0 |= CLEN0_C3EN__ENABLE; 118 | RESTORE_PAGE; 119 | } 120 | 121 | 122 | void CLU3_disable(void) 123 | { 124 | DECL_PAGE; 125 | SET_PAGE(SFRPAGE_CLU); 126 | CLEN0 &= ~CLEN0_C3EN__BMASK; 127 | RESTORE_PAGE; 128 | } 129 | 130 | 131 | void CLU3_enablePinOutput(void) 132 | { 133 | DECL_PAGE; 134 | SET_PAGE(SFRPAGE_CLU); 135 | CLU3CF |= CLU3CF_OEN__ENABLE; 136 | RESTORE_PAGE; 137 | } 138 | 139 | void CLU3_disablePinOutput(void) 140 | { 141 | DECL_PAGE; 142 | SET_PAGE(SFRPAGE_CLU); 143 | CLU3CF &= ~CLU3CF_OEN__BMASK; 144 | RESTORE_PAGE; 145 | } 146 | 147 | bool CLU3_getOutput(void) 148 | { 149 | bool output; 150 | DECL_PAGE; 151 | SET_PAGE(SFRPAGE_CLU); 152 | 153 | output = (CLOUT0 & CLOUT0_C3OUT__BMASK) == CLOUT0_C3OUT__BMASK; 154 | 155 | RESTORE_PAGE; 156 | return output; 157 | } 158 | --------------------------------------------------------------------------------