Skip to content

Commit

Permalink
linux boards (ocpoc, bbblue, navio2) replace custom adc drivers with …
Browse files Browse the repository at this point in the history
…simple px4_arch implementation
  • Loading branch information
dagar committed Jan 7, 2020
1 parent fc9df31 commit d19f18d
Show file tree
Hide file tree
Showing 38 changed files with 528 additions and 1,065 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ src/lib/parameters/px4_parameters_public.h
src/lib/version/build_git_version.h
src/modules/simulator/simulator_config.h
src/systemcmds/topic_listener/listener_generated.cpp

# SITL
dataman
eeprom/
2 changes: 1 addition & 1 deletion boards/aerotenna/ocpoc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
#
############################################################################

add_subdirectory(ocpoc_adc)
add_subdirectory(adc)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2015-2017 PX4 Development Team. All rights reserved.
# Copyright (c) 2020 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -31,9 +31,6 @@
#
############################################################################

px4_add_module(
MODULE drivers__ocpoc_adc
MAIN ocpoc_adc
SRCS
ocpoc_adc.cpp
)
px4_add_library(arch_adc
adc.cpp
)
98 changes: 98 additions & 0 deletions boards/aerotenna/ocpoc/adc/adc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/****************************************************************************
*
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/

#include <board_config.h>

#include <drivers/drv_adc.h>

#include <px4_platform_common/log.h>

#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>

#define ADC_SYSFS_PATH "/sys/bus/iio/devices/iio:device0"
#define ADC_MAX_CHAN 9
int _channels_fd[ADC_MAX_CHAN];

int px4_arch_adc_init(uint32_t base_address)
{
for (int i = 0; i < ADC_MAX_CHAN; i++) {
_channels_fd[i] = -1;
}

return 0;
}

void px4_arch_adc_uninit(uint32_t base_address)
{
for (int i = 0; i < ADC_MAX_CHAN; i++) {
::close(_channels_fd[i]);
_channels_fd[i] = -1;
}
}

uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
{
if (channel > ADC_MAX_CHAN) {
PX4_ERR("channel %d out of range: %d", channel, ADC_MAX_CHAN);
return UINT32_MAX; // error
}

// open channel if necessary
if (_channels_fd[channel] == -1) {
// ADC_SYSFS_PATH
char channel_path[strlen(ADC_SYSFS_PATH) + 20] {};

if (sprintf(channel_path, "%s/in_voltage%d_raw", ADC_SYSFS_PATH, channel) == -1) {
PX4_ERR("adc channel: %d\n", channel);
return UINT32_MAX; // error
}

_channels_fd[channel] = ::open(channel_path, O_RDONLY);
}

char buffer[10] {};

if (::pread(_channels_fd[channel], buffer, sizeof(buffer), 0) < 0) {
PX4_ERR("read channel %d failed", channel);
return UINT32_MAX; // error
}

return atoi(buffer);
}

uint32_t px4_arch_adc_dn_fullcount()
{
return 1 << 12; // 12 bit ADC
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -31,9 +31,8 @@
*
****************************************************************************/

#include <drivers/drv_adc.h>
#pragma once

uint32_t px4_arch_adc_dn_fullcount(void)
{
return 1 << 12; // 12 bit ADC
}
#define SYSTEM_ADC_BASE 0 // not used

#define px4_arch_adc_temp_sensor_mask() (0)
Loading

0 comments on commit d19f18d

Please sign in to comment.