Skip to content

Commit

Permalink
Merge branch 'update'
Browse files Browse the repository at this point in the history
  • Loading branch information
pjueon committed Jan 12, 2022
2 parents b725ba5 + 378648c commit 4de1982
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 160 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.2)
include(GNUInstallDirs)
SET(CMAKE_CXX_STANDARD 14)

SET(LIBRARY_VERSION "1.0.4")
SET(LIBRARY_VERSION "1.1.0")
SET(LIBRARY_SOVERSION "1")

SET (UDEVRULES_INSTALL_DIR "/lib/udev/rules.d" CACHE STRING "Base directory for udev rules")
Expand Down
2 changes: 1 addition & 1 deletion include/JetsonGPIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace std

namespace GPIO
{
constexpr auto VERSION = "1.0.4";
constexpr auto VERSION = "1.1.0";
constexpr auto _SYSFS_ROOT = "/sys/class/gpio";

extern const std::string JETSON_INFO;
Expand Down
4 changes: 3 additions & 1 deletion include/private/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ enum class Model
JETSON_XAVIER,
JETSON_TX2,
JETSON_TX1,
JETSON_NANO
JETSON_NANO,
JETSON_TX2_NX
};

// alias
Expand All @@ -46,5 +47,6 @@ constexpr Model JETSON_XAVIER = Model::JETSON_XAVIER;
constexpr Model JETSON_TX2 = Model::JETSON_TX2;
constexpr Model JETSON_TX1 = Model::JETSON_TX1;
constexpr Model JETSON_NANO = Model::JETSON_NANO;
constexpr Model JETSON_TX2_NX = Model::JETSON_TX2_NX;

#endif
11 changes: 10 additions & 1 deletion include/private/gpio_pin_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ DEALINGS IN THE SOFTWARE.
#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <memory>

#include "JetsonGPIO.h"
#include "private/Model.h"
Expand All @@ -54,6 +56,10 @@ struct ChannelInfo
const std::string pwm_chip_dir;
const int pwm_id;

std::shared_ptr<std::fstream> f_direction;
std::shared_ptr<std::fstream> f_value;
std::shared_ptr<std::fstream> f_duty_cycle;

ChannelInfo(const std::string &channel, const std::string &gpio_chip_dir,
// int chip_gpio,
int gpio, const std::string& gpio_name, const std::string &pwm_chip_dir,
Expand All @@ -64,7 +70,10 @@ struct ChannelInfo
gpio(gpio),
gpio_name(gpio_name),
pwm_chip_dir(pwm_chip_dir),
pwm_id(pwm_id)
pwm_id(pwm_id),
f_direction(std::make_shared<std::fstream>()),
f_value(std::make_shared<std::fstream>()),
f_duty_cycle(std::make_shared<std::fstream>())
{}
};

Expand Down
8 changes: 7 additions & 1 deletion samples/simple_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ DEALINGS IN THE SOFTWARE.
#include <JetsonGPIO.h>

using namespace std;
const map<string, int> output_pins{{"JETSON_XAVIER", 18}, {"JETSON_NANO", 33}};
const map<string, int> output_pins{
{"JETSON_XAVIER", 18},
{"JETSON_NANO", 33},
{"JETSON_NX", 33},
{"CLARA_AGX_XAVIER", 18},
{"JETSON_TX2_NX", 32},
};

int get_output_pin()
{
Expand Down
22 changes: 18 additions & 4 deletions samples/test_all_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,21 @@ class APITests
if (model == "CLARA_AGX_XAVIER")
/* Pre-test configuration, if boot-time pinmux doesn't set up PWM pins:
Set BOARD pin 18 as mux function PWM:
bbusybox devmem 0x2434090 32 0x401
busybox devmem 0x2434090 32 0x401
*/
return { 18, 19, 21, 22, {}, "MCLK05", "SOC_GPIO42", { 15, 18 } };

if (model == "JETSON_TX2_NX")
/* Pre-test configuration, if boot-time pinmux doesn't set up PWM pins:
Set BOARD pin 33 as mux function PWM (func 1):
busybox devmem 0x0c3010a8 32 0x401
Set BOARD pin 32 as mux function PWM (func 2):
busybox devmem 0x0c301080 32 0x401
Board mode pins
*/
return { 32, 31, 29, 26, {}, "GPIO09", "AUD_MCLK", { 32, 33 } };


throw std::runtime_error("invalid model");
}

Expand Down Expand Up @@ -552,14 +564,16 @@ class APITests

GPIO::PWM p(pin_data.out_a, 500);
p.start(pct);
constexpr int N = 1000;
constexpr int N = 5000;
for (int i = 0; i < N; i++)
count += GPIO::input(pin_data.in_a);

p.stop();

auto min_ct = 10 * (pct - 5);
auto max_ct = 10 * (pct + 5);
const auto weight = N / 100.0;
const auto delta = 5;
const auto min_ct = weight * (pct - delta);
const auto max_ct = weight * (pct + delta);

assert(min_ct <= count && count <= max_ct);
GPIO::cleanup();
Expand Down
Loading

0 comments on commit 4de1982

Please sign in to comment.