Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeagleBone AI support #203

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
18 changes: 8 additions & 10 deletions library/include/rc/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
* all swiveled around. The ADC2AI() macro will swivel using this table:
*
* AM3358 - AI
* 0 - 4
* 1 - 6
* 2 - 7
* 3 - 5
* 4 - 3
* 5 - 2
* 6 - 0
* 7 - -1 (not available on BeagleBone AI)
* 0 - 0 (X+)
* 1 - 1 (X-)
* 2 - 3 (Y-)
* 3 - 2 (Y+)
* 4 - 7 (IN3)
* 5 - 6 (IN2)
* 6 - 4 (IN0)
* 7 - 5 (IN1 - grounded on BeagleBone AI)
*
* See the rc_test_adc example for sample use case.
*
Expand All @@ -48,8 +48,6 @@
#ifndef RC_ADC_H
#define RC_ADC_H

#define ADC2AI(x) (x==0?4:(x==1?6:(x==2?7:(x==3?5:(x==4?3:(x==5?2:(x==6?0:-1)))))))

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
12 changes: 10 additions & 2 deletions library/src/io/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <fcntl.h> // for open
#include <unistd.h> // for close
#include <rc/adc.h>
#include <rc/model.h>

// preposessor macros
#define unlikely(x) __builtin_expect (!!(x), 0)
Expand All @@ -24,6 +25,7 @@
#define V_DIV_RATIO 11.0
#define BATT_DEADZONE 1.0

#define ADC2AI(x) (x==0?0:(x==1?1:(x==2?3:(x==3?2:(x==4?7:(x==5?6:(x==6?4:(x==7?5:-1))))))))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ugly hack. Not the desired approach. I need to figure out how to do a better job remapping the channels in a more portable way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a series of symlink entries into the device tree to create something like /dev/bone/adc/Px_y? I'd think that would be a better way to handle GPIOs than with the LED drivers like Deepak Khatri did for now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ugly hack. Not the desired approach. I need to figure out how to do a better job remapping the channels in a more portable way.

can we make ADC2AI(x) an inline function


#define CHANNELS 8
#define IIO_DIR "/sys/bus/iio/devices/iio:device0"
Expand All @@ -42,7 +44,10 @@ int rc_adc_init(void)
if(init_flag) return 0;

for(i=0;i<CHANNELS;i++){
snprintf(buf, sizeof(buf), IIO_DIR "/in_voltage%d_raw", i);
if(rc_model()==MODEL_BB_AI || rc_model()==MODEL_BB_AI_RC)
snprintf(buf, sizeof(buf), IIO_DIR "/in_voltage%d_raw", ADC2AI(i));
else
snprintf(buf, sizeof(buf), IIO_DIR "/in_voltage%d_raw", i);
temp_fd = open(buf, O_RDONLY);
if(temp_fd<0){
perror("ERROR in rc_adc_init, failed to open iio adc interface\n");
Expand Down Expand Up @@ -100,7 +105,10 @@ double rc_adc_read_volt(int ch)
{
int raw = rc_adc_read_raw(ch);
if(raw<0) return -1;
return raw * 1.8 / 4095.0;
if(rc_model()==MODEL_BB_AI || rc_model()==MODEL_BB_AI_RC)
return raw * 0.805664062 / 1000.0; // * in_voltage_scale = mV
else
return raw * 1.8 / 4095.0;
}


Expand Down
2 changes: 1 addition & 1 deletion library/src/io/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define likely(x) __builtin_expect (!!(x), 1)

#define DEVICE_BASE "/dev/gpiochip"
#define CHIPS_MAX 6 // up to 6 chip chips, make larger if you want
#define CHIPS_MAX 10 // up to 10 chip chips, make larger if you want
#define MAX_BUF 64


Expand Down
1 change: 0 additions & 1 deletion library/src/pru/pru.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ static volatile unsigned int* shared_mem_32bit_ptr = NULL;

int rc_pru_start(int ch, const char* fw_name)
{
return 0; // until we fix for AM5
int fd, ret;
char buf[64];

Expand Down
3 changes: 1 addition & 2 deletions library/src/pru/servo.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define AM335X_GPIO_POWER_PIN 2,16 //gpio2.16 P8.36
#define AM335X_SERVO_PRU_CH 1 // PRU1
#define AM335X_SERVO_PRU_FW "am335x-pru1-rc-servo-fw"
#define AM57XX_GPIO_POWER_PIN 8,10 //gpio8.10 P8.36
#define AM57XX_GPIO_POWER_PIN 7,10 //gpio8.10 P8.36
#define AM57XX_SERVO_PRU_CH 4 // PRU2_0
#define AM57XX_SERVO_PRU_FW "am57xx-pru2_0-rc-servo-fw"
#define PRU_SERVO_LOOP_INSTRUCTIONS 48 // instructions per PRU servo timer loop
Expand All @@ -33,7 +33,6 @@ static int esc_min_us = RC_ESC_DEFAULT_MIN_US;

int rc_servo_init(void)
{
return 0; // until we update for AM5
int i;
// start gpio power rail pin
if(rc_model()==MODEL_BB_AI || rc_model()==MODEL_BB_AI_RC){
Expand Down
2 changes: 2 additions & 0 deletions pru_firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ install:
@$(INSTALLDIR) $(DESTDIR)/lib/firmware
@$(INSTALLNONEXEC) $(TARGET0) $(DESTDIR)/lib/firmware/
@$(INSTALLNONEXEC) $(TARGET1) $(DESTDIR)/lib/firmware/
@$(INSTALLNONEXEC) $(TARGET2) $(DESTDIR)/lib/firmware/
@$(INSTALLNONEXEC) $(TARGET3) $(DESTDIR)/lib/firmware/
@echo 'PRU Firmware Install Complete'


Expand Down