Skip to content

Commit

Permalink
feat: (bit band) A little bit enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
but0n committed May 2, 2017
1 parent c1835e5 commit 31242a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libs/include/bit.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef BIT_H
#define BIT_H

#define BITBAND(addr, bitnum) ((addr & 0xF0000000) + 0x2000000 + ((addr & 0xFFFFF) << 5) + (bitnum<<2))
#define BIT_ADDR(addr, bitnum) *((volatile unsigned long *)(BITBAND(addr, bitnum)))
#define BITBAND(addr, bitnum) (((addr) & 0xF0000000) + 0x2000000 + (((addr) & 0xFFFFF) << 5) + ((bitnum)<<2))
#define BIT_ADDR(addr, bitnum) *((volatile unsigned long *)(BITBAND((unsigned int)(addr), bitnum)))

#endif
7 changes: 3 additions & 4 deletions libs/include/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

#define SCL_PINNUM 15
#define SDA_PINNUM 14
#define SCL BIT_ADDR((GPIOB_BASE+12), SCL_PINNUM)
#define SDA BIT_ADDR((GPIOB_BASE+12), SDA_PINNUM)
#define SCL BIT_ADDR(&(GPIOB->ODR), SCL_PINNUM)
#define SDA BIT_ADDR(&(GPIOB->ODR), SDA_PINNUM)
//#define AD0 BIT_ADDR((GPIOC_BASE+12), 6)


#define GPIOB_IDR_Addr (GPIOB_BASE + 8)
#define READ_SDA BIT_ADDR(GPIOB_IDR_Addr, SDA_PINNUM)
#define READ_SDA BIT_ADDR(&(GPIOB->IDR), SDA_PINNUM)

#define IIC_DELAY() delay_us(1)

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main() {
uart_sendStr("MPU6050 Connect Success!");
UART_CR();

// xTaskCreate(uart_task, "UART_TASK", 100, NULL, 1, NULL);
xTaskCreate(uart_task, "UART_TASK", 100, NULL, 1, NULL);
xTaskCreate(mpu_task, "MPU_TASK", 100, NULL, 3, NULL);
xTaskCreate(pid_task, "PID_TASK", 100, NULL, 2, NULL);
vTaskStartScheduler();
Expand Down

0 comments on commit 31242a5

Please sign in to comment.