diff --git a/sample-projects/shtc3-stm32-uvision/Source/main.c b/sample-projects/shtc3-stm32-uvision/Source/main.c index 2107656..957172f 100644 --- a/sample-projects/shtc3-stm32-uvision/Source/main.c +++ b/sample-projects/shtc3-stm32-uvision/Source/main.c @@ -29,17 +29,16 @@ * POSSIBILITY OF SUCH DAMAGE. */ - #include "shtc1.h" -#include #include "system.h" +#include static void led_init(void); static void led_blue(bool on); static void led_green(bool on); -#define SCL_LOW() (GPIOB->BSRR = 0x01000000) // set SCL to low -#define SCL_OPEN() (GPIOB->BSRR = 0x00000100) // set SCL to open-drain +#define SCL_LOW() (GPIOB->BSRR = 0x01000000) // set SCL to low +#define SCL_OPEN() (GPIOB->BSRR = 0x00000100) // set SCL to open-drain int main(void) { /* Initialize the i2c bus for the current platform */ @@ -81,30 +80,27 @@ int main(void) { } /* -- adapt this code for your platform -- */ -static void led_init(void) -{ - RCC->APB2ENR |= 0x00000010; /* I/O port C clock enabled */ - GPIOC->CRH &= 0xFFFFFF00; /* set general purpose output mode for LEDs */ - GPIOC->CRH |= 0x00000011; - GPIOC->BSRR = 0x03000000; /* LEDs off */ +static void led_init(void) { + RCC->APB2ENR |= 0x00000010; /* I/O port C clock enabled */ + GPIOC->CRH &= 0xFFFFFF00; /* set general purpose output mode for LEDs */ + GPIOC->CRH |= 0x00000011; + GPIOC->BSRR = 0x03000000; /* LEDs off */ } /* -- adapt this code for your platform -- */ -static void led_blue(bool on) -{ - if(on) { - GPIOC->BSRR = 0x00000100; - } else { - GPIOC->BSRR = 0x01000000; - } +static void led_blue(bool on) { + if (on) { + GPIOC->BSRR = 0x00000100; + } else { + GPIOC->BSRR = 0x01000000; + } } /* -- adapt this code for your platform -- */ -static void led_green(bool on) -{ - if(on) { - GPIOC->BSRR = 0x00000200; - } else { - GPIOC->BSRR = 0x02000000; - } +static void led_green(bool on) { + if (on) { + GPIOC->BSRR = 0x00000200; + } else { + GPIOC->BSRR = 0x02000000; + } } diff --git a/sample-projects/shtc3-stm32-uvision/Source/sensirion_sw_i2c_implementation.c b/sample-projects/shtc3-stm32-uvision/Source/sensirion_sw_i2c_implementation.c index ee007c8..4548a23 100644 --- a/sample-projects/shtc3-stm32-uvision/Source/sensirion_sw_i2c_implementation.c +++ b/sample-projects/shtc3-stm32-uvision/Source/sensirion_sw_i2c_implementation.c @@ -36,37 +36,35 @@ // I2C IO-Pins /* -- adapt the defines for your uC -- */ // SDA on port B, bit 9 -#define SDA_LOW() (GPIOB->BSRR = 0x02000000) // set SDA to low -#define SDA_OPEN() (GPIOB->BSRR = 0x00000200) // set SDA to open-drain -#define SDA_READ() (GPIOB->IDR & 0x0200) // read SDA +#define SDA_LOW() (GPIOB->BSRR = 0x02000000) // set SDA to low +#define SDA_OPEN() (GPIOB->BSRR = 0x00000200) // set SDA to open-drain +#define SDA_READ() (GPIOB->IDR & 0x0200) // read SDA // SCL on port B, bit 8 /* -- adapt the defines for your uC -- */ -#define SCL_LOW() (GPIOB->BSRR = 0x01000000) // set SCL to low -#define SCL_OPEN() (GPIOB->BSRR = 0x00000100) // set SCL to open-drain -#define SCL_READ() (GPIOB->IDR & 0x0100) // read SCL +#define SCL_LOW() (GPIOB->BSRR = 0x01000000) // set SCL to low +#define SCL_OPEN() (GPIOB->BSRR = 0x00000100) // set SCL to open-drain +#define SCL_READ() (GPIOB->IDR & 0x0100) // read SCL /** * Initialize all hard- and software components that are needed to set the * SDA and SCL pins. */ -void sensirion_init_pins(void) -{ - RCC->APB2ENR |= 0x00000008; // I/O port B clock enabled +void sensirion_init_pins(void) { + RCC->APB2ENR |= 0x00000008; // I/O port B clock enabled - SDA_OPEN(); // I2C-bus idle mode SDA released - SCL_OPEN(); // I2C-bus idle mode SCL released + SDA_OPEN(); // I2C-bus idle mode SDA released + SCL_OPEN(); // I2C-bus idle mode SCL released - // SDA on port B, bit 9 - // SCL on port B, bit 8 - GPIOB->CRH &= 0xFFFFFF00; // set open-drain output for SDA and SCL - GPIOB->CRH |= 0x00000055; // + // SDA on port B, bit 9 + // SCL on port B, bit 8 + GPIOB->CRH &= 0xFFFFFF00; // set open-drain output for SDA and SCL + GPIOB->CRH |= 0x00000055; // } void sensirion_release_pins(void) { - // do nothing + // do nothing } - /** * Configure the SDA pin as an input. With an external pull-up resistor the line * should be left floating, without external pull-up resistor, the input must be @@ -128,10 +126,10 @@ uint8_t sensirion_SCL_read() { * @param useconds the sleep time in microseconds */ void sensirion_sleep_usec(uint32_t useconds) { - for(uint32_t i = 0; i < useconds; i++) { - __nop(); // nop's may be added or removed for timing adjustment - __nop(); - __nop(); - __nop(); - } + for (uint32_t i = 0; i < useconds; i++) { + __nop(); // nop's may be added or removed for timing adjustment + __nop(); + __nop(); + __nop(); + } } diff --git a/sample-projects/shtc3-stm32-uvision/Source/system.c b/sample-projects/shtc3-stm32-uvision/Source/system.c index e3c211b..d40bb09 100644 --- a/sample-projects/shtc3-stm32-uvision/Source/system.c +++ b/sample-projects/shtc3-stm32-uvision/Source/system.c @@ -14,5 +14,5 @@ #include "system.h" //------------------------------------------------------------------------------ -void SystemInit(void){ +void SystemInit(void) { } diff --git a/sample-projects/shtc3-stm32-uvision/Source/system.h b/sample-projects/shtc3-stm32-uvision/Source/system.h index 9b0e430..0a15f5f 100644 --- a/sample-projects/shtc3-stm32-uvision/Source/system.h +++ b/sample-projects/shtc3-stm32-uvision/Source/system.h @@ -15,15 +15,15 @@ #define SYSTEM_H //-- Includes ------------------------------------------------------------------ -#include // controller register definitions +#include // controller register definitions //-- Enumerations -------------------------------------------------------------- // Error codes -typedef enum{ - NO_ERROR = 0x00, // no error - ACK_ERROR = 0x01, // no acknowledgment error - CHECKSUM_ERROR = 0x02 // checksum mismatch error -}etError; +typedef enum { + NO_ERROR = 0x00, // no error + ACK_ERROR = 0x01, // no acknowledgment error + CHECKSUM_ERROR = 0x02 // checksum mismatch error +} etError; //============================================================================== void SystemInit(void);