Commit 70decacb authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added basi support for the zigbee module.

parent 656d598a
......@@ -10,6 +10,7 @@ TARGET_FILES+=src/gpio.c
TARGET_FILES+=src/eeprom.c
TARGET_FILES+=src/ram.c
TARGET_FILES+=src/adc_dma.c
TARGET_FILES+=src/zigbee.c
TARGET_FILES+=src/bioloid_time.c
TARGET_FILES+=src/bioloid_dyn_slave.c
TARGET_FILES+=src/bioloid_dyn_master_sensors.c
......
......@@ -7,10 +7,13 @@ extern "C" {
#include "stm32f4xx_hal.h"
// public functions
void adc_init(void);
void adc_start(void);
void adc_set_period(uint8_t period_ms);
void adc_stop(void);
// operation functions
void adc_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data);
#ifdef __cplusplus
}
......
......@@ -64,7 +64,14 @@ typedef enum {
BIOLOID_ADC_VREF_L = 0x3E,
BIOLOID_ADC_VREF_H = 0x3F,
BIOLOID_ADC_CH8_L = 0x40,
BIOLOID_ADC_CH8_H = 0x41
BIOLOID_ADC_CH8_H = 0x41,
BIOLOID_ZIGBEE_CNTRL = 0x42,
BIOLOID_ZIGBEE_BAUDRATE = 0x43,
BIOLOID_ZIGBEE_OWN_ID_L = 0x44,
BIOLOID_ZIGBEE_OWN_ID_H = 0x45,
BIOLOID_ZIGBEE_REM_ID_L = 0x46,
BIOLOID_ZIGBEE_REM_ID_H = 0x47,
} bioloid_registers;
#define GPIO_BASE_ADDRESS 0x20
......@@ -76,6 +83,12 @@ typedef enum {
#define GPIO_INT_EN 0x02
#define GPIO_INT_FLAG 0x04
#define ADC_BASE_ADDRESS 0x30
#define ADC_MEM_LENGTH 18
#define ZIGBEE_BASE_ADDRESS 0x42
#define ZIGBEE_MEM_LENGTH 6
#ifdef __cplusplus
}
#endif
......
#ifndef _ZIGBEE_H
#define _ZIGBEE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx_hal.h"
// public functions
void zigbee_init(void);
void zigbee_enable_power(void);
void zigbee_disable_power(void);
void zigbee_enable(void);
void zigbee_disable(void);
// operation functions
void zigbee_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data);
#ifdef __cplusplus
}
#endif
#endif
......@@ -368,3 +368,15 @@ void adc_stop(void)
HAL_TIM_OC_Stop_IT(&ADC_TIM_Handle, TIM_CHANNEL_4);
}
void adc_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data)
{
if(ram_in_range(BIOLOID_ADC_CNTRL,address,length))
{
if(data[BIOLOID_ADC_CNTRL-address]&0x01)
adc_start();
else
adc_stop();
}
if(ram_in_range(BIOLOID_ADC_PERIOD,address,length))
adc_set_period(data[BIOLOID_ADC_PERIOD-address]);
}
......@@ -4,6 +4,8 @@
#include "ram.h"
#include "eeprom.h"
#include "gpio.h"
#include "adc_dma.h"
#include "zigbee.h"
/* external interrupt pin */
#define DYN_SLAVE_EXT_INT_PIN GPIO_PIN_8
......@@ -66,6 +68,12 @@ unsigned char bioloid_on_write(unsigned short int address,unsigned short int len
// GPIO commands
if(ram_in_window(GPIO_BASE_ADDRESS,GPIO_MEM_LENGTH,address,length))
gpio_process_write_cmd(address,length,data);
// ADC commands
if(ram_in_window(ADC_BASE_ADDRESS,ADC_MEM_LENGTH,address,length))
adc_process_write_cmd(address,length,data);
// Zigbee commands
if(ram_in_window(ZIGBEE_BASE_ADDRESS,ZIGBEE_MEM_LENGTH,address,length))
zigbee_process_write_cmd(address,length,data);
// write eeprom
for(i=address,j=0;i<LAST_EEPROM_OFFSET && i<(address+length);i++,j++)
EE_WriteVariable(i,data[j]);
......
......@@ -3,6 +3,7 @@
#include "eeprom.h"
#include "ram.h"
#include "adc_dma.h"
#include "zigbee.h"
#include "bioloid_time.h"
#include "bioloid_dyn_slave.h"
#include "bioloid_dyn_master_sensors.h"
......@@ -20,6 +21,8 @@ int32_t main(void)
adc_init();
/* initialize the time module */
bioloid_time_init();
/* initialize zigbee module */
zigbee_init();
/* initialize the dynamixel slave interface */
bioloid_dyn_slave_init();
bioloid_dyn_slave_start();
......
#include "zigbee.h"
#include "ram.h"
#define ENABLE_ZIGBEE_PWR_GPIO_CLK __HAL_RCC_GPIOC_CLK_ENABLE()
#define ZIGBEE_PWR_PIN GPIO_PIN_12
#define ZIGBEE_PWR_GPIO_PORT GPIOC
// private variables
// public functions
void zigbee_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ENABLE_ZIGBEE_PWR_GPIO_CLK;
/* initlaize GPIO pins */
GPIO_InitStructure.Pin = ZIGBEE_PWR_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ZIGBEE_PWR_GPIO_PORT, &GPIO_InitStructure);
// disable power by default
zigbee_disable_power();
}
void zigbee_enable_power(void)
{
HAL_GPIO_WritePin(ZIGBEE_PWR_GPIO_PORT,ZIGBEE_PWR_PIN,GPIO_PIN_RESET);
ram_data[BIOLOID_ZIGBEE_CNTRL]|=0x01;
}
void zigbee_disable_power(void)
{
HAL_GPIO_WritePin(ZIGBEE_PWR_GPIO_PORT,ZIGBEE_PWR_PIN,GPIO_PIN_SET);
ram_data[BIOLOID_ZIGBEE_CNTRL]&=0xFE;
}
void zigbee_enable(void)
{
ram_data[BIOLOID_ZIGBEE_CNTRL]|=0x02;
}
void zigbee_disable(void)
{
ram_data[BIOLOID_ZIGBEE_CNTRL]&=0xFD;
}
// operation functions
void zigbee_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data)
{
if(ram_in_range(BIOLOID_ZIGBEE_CNTRL,address,length))
{
if(data[BIOLOID_ZIGBEE_CNTRL-address]&0x01)
zigbee_enable_power();
else
zigbee_disable_power();
if(data[BIOLOID_ZIGBEE_CNTRL-address]&0x02)
zigbee_enable();
else
zigbee_disable();
}
}
Supports Markdown
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