Skip to content

Commit

Permalink
Fix style issues in uvision sample project (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Sep 13, 2019
1 parent bf93e53 commit d5d2595
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 54 deletions.
44 changes: 20 additions & 24 deletions sample-projects/shtc3-stm32-uvision/Source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/


#include "shtc1.h"
#include <stdbool.h>
#include "system.h"
#include <stdbool.h>

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 */
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion sample-projects/shtc3-stm32-uvision/Source/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
#include "system.h"

//------------------------------------------------------------------------------
void SystemInit(void){
void SystemInit(void) {
}
12 changes: 6 additions & 6 deletions sample-projects/shtc3-stm32-uvision/Source/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#define SYSTEM_H

//-- Includes ------------------------------------------------------------------
#include <stm32f10x.h> // controller register definitions
#include <stm32f10x.h> // 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);
Expand Down

0 comments on commit d5d2595

Please sign in to comment.