Skip to content

SNS - GPIO - #34

Open
Knhwong wants to merge 24 commits into
masterfrom
ss-gpioNew
Open

SNS - GPIO#34
Knhwong wants to merge 24 commits into
masterfrom
ss-gpioNew

Conversation

@Knhwong

@Knhwong Knhwong commented Nov 4, 2022

Copy link
Copy Markdown

All primary functionality done, I'll need to ask more about logging since using the pointers makes it harder to find problems.

@ishmis ishmis changed the title Initial Commitment SNS - GPIO Nov 5, 2022
@ishmis ishmis assigned ishmis and Knhwong and unassigned ishmis Nov 5, 2022
@ishmis ishmis added the sensors Sensors Project label Nov 5, 2022
@ishmis

ishmis commented Nov 5, 2022

Copy link
Copy Markdown
Contributor

Please git merge master and resolve conflicts

@ishmis ishmis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also, the scripts folder should not be touched at all

Comment thread lib/io/hardware_gpio.hpp Outdated
Comment on lines +48 to +60
//GPIO Start Addr End Addr
//GPIO0 0x44E0_7000 0x44E0_7FFF
//GPIO1 0x4804_C000 0x4804_CFFF
//GPIO2 0x481A_C000 0x481A_CFFF
//GPIO3 0x481A_E000 0x481A_EFFF

//GPIO_DATAIN (READ) 0x138h
//GPIO_DATAOUT 0x13c
//SET 0x194
//CLEAR 0x190
// const uint8_t bank = pin_ / 32; // offset: GPIO_0,1,2,3
// const uint8_t pin_id = pin_ % 32;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

commented code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Referenced information for getting pin addresses. Can delete but anybody later on reading might find it useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's stuff you need to actually use in the code itself, don't keep it commented and just comment on the method that needs it desribing briefly how to use it.

Comment thread lib/io/hardware_gpio.cpp Outdated
Comment thread lib/io/hardware_gpio.cpp Outdated
Comment on lines +66 to +67
std::shared_ptr<HardwareGpioReader> reader;
return reader;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just returning an uninitialized reader?

Comment thread lib/io/hardware_gpio.cpp Outdated
Comment on lines +92 to +93
std::shared_ptr<HardwareGpioWriter> writer;
return writer;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uninitialized writer

Comment thread lib/io/hardware_gpio.cpp Outdated
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

formatting

Comment thread lib/io/hardware_gpio.cpp Outdated
// TODO: implement
throw -1;

int out = *gpio_readAddr & pinMAP;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const and style guide (naming)

Comment thread lib/io/hardware_gpio.cpp Outdated
GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state)
{
// TODO: implement
//Not sure if this correct

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Multiline comments?

Comment thread lib/io/hardware_gpio.cpp Outdated
//May just erase everything
//May need to
if (state == core::DigitalSignal::kHigh) {
*gpio_setAddr |= pinMAP;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

naming

Comment thread lib/io/hardware_gpio.cpp Outdated
}



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

formatting

Comment thread lib/io/hardware_gpio.cpp Outdated

const off_t pinAddress = bankAddresses[bank];
volatile void *gpio_addr;
volatile unsigned int *gpio_set;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

uint?

Comment thread lib/io/hardware_gpio.hpp Outdated




Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

formatting

Comment thread lib/io/hardware_gpio.hpp Outdated
*/

//GPIO Start Addr End Addr
//GPIO0 0x44E0_7000 0x44E0_7FFF

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

multiline comment...

Comment thread lib/io/hardware_gpio.hpp Outdated

private:
hyped::core::ILogger &log_;
const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where are these values from? Is it documented somewhere?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Taken from old code and also cross referenced from AM335x technical reference manual along with other tutorials.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok sounds good. Is this documented somewhere so that someone next year can know where these values came from?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also in general "it was in the old codebase" is not justification. We are writing a new system here with lots of new components and there was lots of flawed legacy code in the 2022 codebase. If you are ever unsure of a value, please either ask someone who may already know (i.e. @SnickeyX) or find the relevant datasheet and document where the values came from.

Comment thread lib/io/hardware_gpio.hpp Outdated
std::unordered_map<uint8_t, std::shared_ptr<IGpioWriter>> InitializedWriters;
std::unordered_map<uint8_t, std::shared_ptr<IGpioReader>> InitializedReaders;

static constexpr unsigned int pinSize = 0x1000;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

uint and naming

@Knhwong Knhwong mentioned this pull request Nov 7, 2022
@ishmis

ishmis commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

This PR definitely needs to be prioritized, @Knhwong don't think you updated the code here with the testing code that worked?

@Knhwong

Knhwong commented Dec 27, 2022

Copy link
Copy Markdown
Author

This PR definitely needs to be prioritized, @Knhwong don't think you updated the code here with the testing code that worked?

I sent you the testing code in a slack message, it was a basic main.cpp file that was a condensed gpio. The changes aka just type fixes were already updated in the main code.

@ishmis

ishmis commented Dec 28, 2022

Copy link
Copy Markdown
Contributor

This PR definitely needs to be prioritized, @Knhwong don't think you updated the code here with the testing code that worked?

I sent you the testing code in a slack message, it was a basic main.cpp file that was a condensed gpio. The changes aka just type fixes were already updated in the main code.

are you not planning on updating it here?

@Knhwong

Knhwong commented Dec 29, 2022

Copy link
Copy Markdown
Author

This PR definitely needs to be prioritized, @Knhwong don't think you updated the code here with the testing code that worked?

I sent you the testing code in a slack message, it was a basic main.cpp file that was a condensed gpio. The changes aka just type fixes were already updated in the main code.

are you not planning on updating it here?

By "main" I am referring to this branch. In the main.cpp testing code, it's the same lines updated already within the getwriter or getreader on hardware_gpio.cpp back in the added comments and fixed_types commit. Or are you referring to something else here?

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

scripts/ doesn't contain anything

Comment thread lib/io/hardware_gpio.cpp Outdated
Comment on lines +14 to +20
const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0;

if (out > 0) {
return core::DigitalSignal::kHigh;
} else {
return core::DigitalSignal::kLow;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if (*gpio_readAddr & pinMAP)
also this method doesn't need to be optional

Comment thread lib/io/hardware_gpio.cpp
} else {
*gpio_clearAddr = pinMAP;
}
return core::Result::kSuccess;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can't return kFailure so no reason for returning a result

Comment thread lib/io/hardware_gpio.cpp Outdated
// Integer divison to get bank number
const std::uint32_t bank = pin / 32;
// Modulo by 32 gets us the ID of the pin relative to the bank
const std::uint32_t pinID = pin % 32;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pin_id

Comment thread lib/io/hardware_gpio.cpp Outdated
// Modulo by 32 gets us the ID of the pin relative to the bank
const std::uint32_t pinID = pin % 32;
// Gpio addresses contain 32 pins, so we use pinmap to specify specific pin.
const std::uint32_t pinMAP = (1 << pinID);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pin_map unless MAP is an acronym then expand it

Comment thread lib/io/hardware_gpio.cpp Outdated
}

// Get memory address from bank address
const off_t pinAddress = bankAddresses[bank];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pin_address

Comment thread lib/io/hardware_gpio.cpp Outdated
Comment on lines +98 to +99
const std::uint32_t pinID = pin % 32;
const std::uint32_t pinMAP = (1 << pinID);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same naming issues as in getReader

Comment thread lib/io/hardware_gpio.hpp Outdated
// Bank Addresses are header base addresses.
// Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible

const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bank_addresses, also should use c++ style array

Comment thread lib/io/hardware_gpio.hpp Outdated

const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000};
std::unordered_map<std::uint8_t, std::shared_ptr<IGpioWriter>> InitializedWriters;
std::unordered_map<std::uint8_t, std::shared_ptr<IGpioReader>> InitializedReaders;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

initialised_writers_ and initialised_readers_

Comment thread lib/io/hardware_gpio.hpp Outdated
static constexpr std::uint32_t pinSize = 0x1000;
static constexpr std::uint32_t pinRead = 0x138;
static constexpr std::uint32_t pinClear = 0x190;
static constexpr std::uint32_t pinSet = 0x194;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

kPinSize, kPinRead and so on

Comment thread lib/io/hardware_gpio.hpp Outdated

private:
HardwareGpioReader();
HardwareGpioReader(std::uint8_t pin, volatile std::uint32_t *read)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const for pin

Comment thread lib/io/hardware_gpio.hpp
Comment on lines +12 to +15
static constexpr std::uint32_t pin_size = 0x1000;
static constexpr std::uint32_t pin_read = 0x138;
static constexpr std::uint32_t pin_clear = 0x190;
static constexpr std::uint32_t pin_set = 0x194;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these become private static constexprs following the style guide discussion

unless they need to be accessed outside of methods

Comment thread lib/io/hardware_gpio.cpp

namespace hyped::io {

std::optional<core::DigitalSignal> HardwareGpioReader::read()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional with no nullopt return, so can just have return type core::DigitalSignal

@TomLonergan03

Copy link
Copy Markdown
Contributor

also what are the prehook etc files, they seem to be empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sensors Sensors Project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants