mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #60 from kwagyeman/master
Cleaned up some whitespace and unnecessary header.
This commit is contained in:
commit
d850325de4
@ -7,10 +7,11 @@
|
||||
*
|
||||
*/
|
||||
#include <stm32f4xx.h>
|
||||
#include <core_cm4.h>
|
||||
#include <core_cmInstr.h>
|
||||
#include "mutex.h"
|
||||
|
||||
// This is a standard implementation of mutexs on ARM processors following the ARM guide.
|
||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHEJCHB.html
|
||||
|
||||
void mutex_init(mutex_t *mutex)
|
||||
{
|
||||
mutex_unlock(mutex);
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "ringbuf.h"
|
||||
|
||||
void ring_buf_init(ring_buf_t *buf)
|
||||
@ -26,9 +25,9 @@ void ring_buf_put(ring_buf_t *buf, uint8_t c)
|
||||
/*buffer is full*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
buf->data[buf->tail] = c;
|
||||
buf->tail = (buf->tail + 1) % BUFFER_SIZE;
|
||||
buf->tail = (buf->tail + 1) % BUFFER_SIZE;
|
||||
}
|
||||
|
||||
uint8_t ring_buf_get(ring_buf_t *buf)
|
||||
@ -38,7 +37,7 @@ uint8_t ring_buf_get(ring_buf_t *buf)
|
||||
/*buffer is empty*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
c = buf->data[buf->head];
|
||||
buf->head = (buf->head + 1) % BUFFER_SIZE;
|
||||
return c;
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#define BUFFER_SIZE (1024)
|
||||
|
||||
typedef struct ring_buffer {
|
||||
volatile uint32_t head;
|
||||
volatile uint32_t head;
|
||||
volatile uint32_t tail;
|
||||
uint8_t data[BUFFER_SIZE];
|
||||
} ring_buf_t;
|
||||
|
||||
@ -6,14 +6,14 @@
|
||||
* SCCB (I2C like) driver.
|
||||
*
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stm32f4xx_hal.h>
|
||||
#include "sccb.h"
|
||||
#include "stdbool.h"
|
||||
#include "systick.h"
|
||||
#include <systick.h>
|
||||
#include "omv_boardconfig.h"
|
||||
#define SCCB_FREQ (100000)
|
||||
#define TIMEOUT (10000)
|
||||
|
||||
#include "sccb.h"
|
||||
#define SCCB_FREQ (100000) // We don't need fast I2C. 100KHz is fine here.
|
||||
#define TIMEOUT (1000) /* Can't be sure when I2C routines return. Interrupts
|
||||
while polling hardware may result in unknown delays. */
|
||||
static I2C_HandleTypeDef I2CHandle;
|
||||
|
||||
int SCCB_Init()
|
||||
@ -24,7 +24,7 @@ int SCCB_Init()
|
||||
I2CHandle.Init.ClockSpeed = SCCB_FREQ;
|
||||
I2CHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
|
||||
I2CHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
I2CHandle.Init.GeneralCallMode = I2C_GENERALCALL_ENABLED;
|
||||
I2CHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
|
||||
I2CHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
|
||||
I2CHandle.Init.OwnAddress1 = 0xFE;
|
||||
I2CHandle.Init.OwnAddress2 = 0xFE;
|
||||
@ -46,37 +46,35 @@ uint8_t SCCB_Probe()
|
||||
slv_addr = i;
|
||||
break;
|
||||
}
|
||||
systick_sleep(1);
|
||||
if (i!=126) {
|
||||
systick_sleep(1); // Necessary for OV7725 camera (not for OV2640).
|
||||
}
|
||||
}
|
||||
return slv_addr;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
||||
{
|
||||
uint8_t data=0;
|
||||
|
||||
__disable_irq();
|
||||
if((HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, ®, 1, TIMEOUT) != HAL_OK)
|
||||
|| (HAL_I2C_Master_Receive(&I2CHandle, slv_addr, &data, 1, TIMEOUT) != HAL_OK)) {
|
||||
data=0xFF;
|
||||
}
|
||||
__enable_irq();
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
|
||||
{
|
||||
uint8_t ret=0;
|
||||
uint8_t buf[] = {reg, data};
|
||||
|
||||
__disable_irq();
|
||||
if (HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, buf, 2, TIMEOUT) != HAL_OK) {
|
||||
if(HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, buf, 2, TIMEOUT) != HAL_OK) {
|
||||
ret=0xFF;
|
||||
}
|
||||
__enable_irq();
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
|
||||
{
|
||||
uint8_t data=0;
|
||||
|
||||
__disable_irq();
|
||||
if (HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, ®, 1, TIMEOUT) != HAL_OK) {
|
||||
data = 0xFF;
|
||||
goto error_w;
|
||||
}
|
||||
if (HAL_I2C_Master_Receive(&I2CHandle, slv_addr, &data, 1, TIMEOUT) != HAL_OK) {
|
||||
data = 0xFF;
|
||||
}
|
||||
error_w:
|
||||
__enable_irq();
|
||||
return data;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user