Commit da198fdd authored by Keijo Länsikunnas's avatar Keijo Länsikunnas
Browse files

Added more examples in the main. Started working on gyro driver.

parent a6a66f3c
......@@ -89,13 +89,6 @@
<PropertyDeltas />
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="Systick.c" persistent="ZumoLibrary\Systick.c">
<Hidden v="False" />
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
<build_action v="SOURCE_C;;;;" />
<PropertyDeltas />
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="Retarget.c" persistent="ZumoLibrary\Retarget.c">
<Hidden v="False" />
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
......
......@@ -3,11 +3,107 @@
* @brief Basic methods for operating gyroscope. For more details, please refer to Gyro.h file.
* @details part number: L3GD20H (included in Zumo shield)
*/
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "I2C_Common.h"
#include "Gyro.h"
// register addresses
enum regAddr
{
WHO_AM_I = 0x0F,
CTRL1 = 0x20, // D20H
CTRL_REG1 = 0x20, // D20, 4200D
CTRL2 = 0x21, // D20H
CTRL_REG2 = 0x21, // D20, 4200D
CTRL3 = 0x22, // D20H
CTRL_REG3 = 0x22, // D20, 4200D
CTRL4 = 0x23, // D20H
CTRL_REG4 = 0x23, // D20, 4200D
CTRL5 = 0x24, // D20H
CTRL_REG5 = 0x24, // D20, 4200D
REFERENCE = 0x25,
OUT_TEMP = 0x26,
STATUS = 0x27, // D20H
STATUS_REG = 0x27, // D20, 4200D
OUT_X_L = 0x28,
OUT_X_H = 0x29,
OUT_Y_L = 0x2A,
OUT_Y_H = 0x2B,
OUT_Z_L = 0x2C,
OUT_Z_H = 0x2D,
FIFO_CTRL = 0x2E, // D20H
FIFO_CTRL_REG = 0x2E, // D20, 4200D
FIFO_SRC = 0x2F, // D20H
FIFO_SRC_REG = 0x2F, // D20, 4200D
IG_CFG = 0x30, // D20H
INT1_CFG = 0x30, // D20, 4200D
IG_SRC = 0x31, // D20H
INT1_SRC = 0x31, // D20, 4200D
IG_THS_XH = 0x32, // D20H
INT1_THS_XH = 0x32, // D20, 4200D
IG_THS_XL = 0x33, // D20H
INT1_THS_XL = 0x33, // D20, 4200D
IG_THS_YH = 0x34, // D20H
INT1_THS_YH = 0x34, // D20, 4200D
IG_THS_YL = 0x35, // D20H
INT1_THS_YL = 0x35, // D20, 4200D
IG_THS_ZH = 0x36, // D20H
INT1_THS_ZH = 0x36, // D20, 4200D
IG_THS_ZL = 0x37, // D20H
INT1_THS_ZL = 0x37, // D20, 4200D
IG_DURATION = 0x38, // D20H
INT1_DURATION = 0x38, // D20, 4200D
LOW_ODR = 0x39 // D20H
};
#define D20_SA0_HIGH_ADDRESS 0b1101011 // also applies to D20H
void writeReg(uint8 reg, uint8 value)
{
I2C_Write(D20_SA0_HIGH_ADDRESS, reg, value);
}
uint8 readReg(uint8 reg)
{
return I2C_Read(D20_SA0_HIGH_ADDRESS, reg);
}
void read(void)
{
uint8 data[6];
int16 x;
int16 y;
int16 z;
I2C_Read_Multiple(D20_SA0_HIGH_ADDRESS, OUT_X_L | 0x80, data, 6);
x = (int16) ((data[1] << 8) | data[0]);
y = (int16) ((data[3] << 8) | data[2]);
z = (int16) ((data[5] << 8) | data[4]);
printf("%d, %d, %d\n", x, y, z);
}
void enableDefault(void)
{
// 0x00 = 0b00000000
// Low_ODR = 0 (low speed ODR disabled)
writeReg(LOW_ODR, 0x00);
// 0x00 = 0b00000000
// FS = 00 (+/- 250 dps full scale)
writeReg(CTRL_REG4, 0x00);
// 0x6F = 0b01101111
// DR = 01 (200 Hz ODR); BW = 10 (50 Hz bandwidth); PD = 1 (normal mode); Zen = Yen = Xen = 1 (all axes enabled)
writeReg(CTRL_REG1, 0x6F);
}
uint16 value_convert_gyro(uint16 raw)
{
float rate_result;
......@@ -19,9 +115,35 @@ uint16 value_convert_gyro(uint16 raw)
}
#if 0
void zmain(void *p)
{
(void) p;
I2C_Start();
printf("ID: %02X\n", readReg(WHO_AM_I));
enableDefault();
uint8 data[6];
int16 x;
int16 y;
int16 z;
while(1) {
I2C_Read_Multiple(D20_SA0_HIGH_ADDRESS, OUT_X_L | 0x80, data, 6);
x = (int16) ((data[1] << 8) | data[0]);
y = (int16) ((data[3] << 8) | data[2]);
z = (int16) ((data[5] << 8) | data[4]);
vTaskDelayUntil(200);
}
}
#endif
#if 0
//gyroscope//
int main()
void zmain()
{
CyGlobalIntEnable;
UART_1_Start();
......
......@@ -53,9 +53,24 @@
* @details ** Enable global interrupt since Zumo library uses interrupts. **<br>&nbsp;&nbsp;&nbsp;CyGlobalIntEnable;<br>
*/
#if 1
// Hello World!
void zmain(void *p)
{
(void) p; // we don't use this parameter
printf("\nHello, World!\n");
while(true)
{
vTaskDelay(100); // sleep (in an infinite loop)
}
}
#endif
#if 0
//battery level//
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
ADC_Battery_Start();
......@@ -91,9 +106,9 @@ int zmain(void *p)
}
#endif
#if 1
#if 0
// MQTT test
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
......@@ -120,7 +135,33 @@ int zmain(void *p)
#if 0
// button
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
while(1) {
printf("Press button within 5 seconds!\n");
int i = 50;
while(i > 0) {
if(SW1_Read() == 0) {
break;
}
vTaskDelay(100);
--i;
}
if(i > 0) {
printf("Good work\n");
}
else {
printf("You didn't press the button\n");
}
}
}
#endif
#if 0
// button
void zmain(void *p)
{
(void) p; // we don't use this parameter
printf("\nBoot\n");
......@@ -141,7 +182,6 @@ int zmain(void *p)
if(SW1_Read() == 0) {
led = !led;
BatteryLed_Write(led);
ShieldLed_Write(led);
if(led) printf("Led is ON\n");
else printf("Led is OFF\n");
Beep(1000, 150);
......@@ -154,7 +194,7 @@ int zmain(void *p)
#if 0
//ultrasonic sensor//
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
Ultra_Start(); // Ultra Sonic Start function
......@@ -168,10 +208,36 @@ int zmain(void *p)
}
#endif
#if 0
//IR receiver//
void zmain(void *p)
{
(void) p; // we don't use this parameter
IR_Start();
printf("\n\nIR test\n");
IR_flush(); // clear IR receive buffer
printf("Buffer cleared\n");
bool led = false;
// Toggle led when IR signal is received
for(;;)
{
IR_wait(); // wait for IR command
led = !led;
BatteryLed_Write(led);
if(led) printf("Led is ON\n");
else printf("Led is OFF\n");
}
}
#endif
#if 0
//IR receiver//
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
IR_Start();
......@@ -183,18 +249,14 @@ int zmain(void *p)
IR_flush(); // clear IR receive buffer
printf("Buffer cleared\n");
IR_wait(); // wait for IR command
printf("IR command received\n");
// print received IR pulses and their lengths
for(;;)
{
if(IR_get(&IR_val)) {
if(IR_get(&IR_val, portMAX_DELAY)) {
int l = IR_val & IR_SIGNAL_MASK; // get pulse length
int b = 0;
if((IR_val & IR_SIGNAL_HIGH) != 0) b = 1; // get pulse state (0/1)
printf("%d %d\r\n",b, l);
//printf("%d %lu\r\n",IR_val & IR_SIGNAL_HIGH ? 1 : 0, (unsigned long) (IR_val & IR_SIGNAL_MASK));
}
}
}
......@@ -203,7 +265,7 @@ int zmain(void *p)
#if 0
//reflectance//
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
struct sensors_ ref;
......@@ -217,12 +279,14 @@ int zmain(void *p)
{
// read raw sensor values
reflectance_read(&ref);
printf("%5d %5d %5d %5d %5d %5d\r\n", ref.l3, ref.l2, ref.l1, ref.r1, ref.r2, ref.r3); // print out each period of reflectance sensors
// print out each period of reflectance sensors
printf("%5d %5d %5d %5d %5d %5d\r\n", ref.l3, ref.l2, ref.l1, ref.r1, ref.r2, ref.r3);
// read digital values that are based on threshold. 0 = white, 1 = black
// when blackness value is over threshold the sensors reads 1, otherwise 0
reflectance_digital(&dig); //print out 0 or 1 according to results of reflectance period
printf("%5d %5d %5d %5d %5d %5d \r\n", dig.l3, dig.l2, dig.l1, dig.r1, dig.r2, dig.r3); //print out 0 or 1 according to results of reflectance period
reflectance_digital(&dig);
//print out 0 or 1 according to results of reflectance period
printf("%5d %5d %5d %5d %5d %5d \r\n", dig.l3, dig.l2, dig.l1, dig.r1, dig.r2, dig.r3);
vTaskDelay(200);
}
......@@ -232,7 +296,7 @@ int zmain(void *p)
#if 0
//motor//
int zmain(void *p)
void zmain(void *p)
{
(void) p; // we don't use this parameter
motor_start(); // motor start
......@@ -254,7 +318,7 @@ int zmain(void *p)
#if 0
/* Example of how to use this Accelerometer!!!*/
int zmain(void *p) {
void zmain(void *p) {
(void) p; // we don't use this parameter
struct accData_ data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment