generated from libhal/libhal-__arm_mcu_family__
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Created package for libhal linux on the new repo
- Loading branch information
1 parent
7326ad1
commit 4ec3ee4
Showing
26 changed files
with
914 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM --platform=arm64 ubuntu:22.04 | ||
|
||
RUN apt update && apt upgrade -y | ||
RUN apt install gcc g++ valgrind neofetch git wget python3-pip clang-format software-properties-common locales pkg-config automake autoconf autoconf-archive libtool m4 -y | ||
|
||
RUN wget https://apt.llvm.org/llvm.sh | ||
RUN chmod +x llvm.sh | ||
RUN ./llvm.sh 17 | ||
RUN apt install libc++-17-dev libc++abi-17-dev -y | ||
|
||
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test | ||
RUN apt install -y build-essential g++-12 | ||
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - | ||
RUN add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | ||
RUN apt-get install clang-tidy-17 -y | ||
RUN python3 -m pip install "conan>=2.2.2" cmake | ||
|
||
# Compile gpiod | ||
WORKDIR /opt | ||
RUN git clone https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git | ||
RUN locale-gen "en_US.UTF-8" | ||
WORKDIR /opt/libgpiod | ||
RUN ./autogen.sh --enable-bindings-cxx | ||
RUN make -j | ||
RUN make install | ||
|
||
# Configure conan for libhal | ||
RUN conan remote add libhal-trunk https://libhal.jfrog.io/artifactory/api/conan/trunk-conan | ||
RUN conan config install -sf profiles/baremetal/v2 https://github.com/libhal/conan-config.git | ||
RUN conan profile detect --force | ||
# Set profile based on arch x86 or arm64 | ||
# RUN if [[ -z "$arg" ]] ; then echo Argument not provided ; else echo Argument is $arg ; fi | ||
RUN conan config install -sf profiles/armv8/linux/ -tf profiles https://github.com/libhal/conan-config.git | ||
|
||
# Test by building demos | ||
RUN mkdir /test_libhal | ||
WORKDIR /test_libhal | ||
RUN git clone https://github.com/libhal/libhal-lpc40 | ||
WORKDIR /test_libhal/libhal-lpc40 | ||
RUN conan config install -sf conan/profiles/v2 -tf profiles https://github.com/libhal/libhal-lpc40.git | ||
RUN conan config install -tf profiles -sf conan/profiles/v1 https://github.com/libhal/arm-gnu-toolchain.git | ||
RUN conan build demos -pr lpc4078 -pr arm-gcc-12.3 -s build_type=MinSizeRel -b missing | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
|
||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I am building a (free) operating system, just a small project, not meant to be anything large |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <iostream> | ||
#include <libhal-linux/input_pin.hpp> | ||
#include <libhal-linux/output_pin.hpp> | ||
#include <libhal/error.hpp> | ||
#include <unistd.h> | ||
|
||
void application() | ||
{ | ||
auto output_gpio = hal::gnu_linux::output_pin("/dev/gpiochip0", 2); | ||
auto input_gpio = hal::gnu_linux::input_pin("/dev/gpiochip0", 3); | ||
std::cout << "blinking gpio 2 on gpiochip0\n"; | ||
bool state = output_gpio.level(); | ||
bool saved_state = false; | ||
while (true) { | ||
output_gpio.level(state); | ||
saved_state = output_gpio.level(); | ||
std::cout << "current state: " << saved_state << std::endl; | ||
sleep(1); | ||
state ^= 1; | ||
if (!input_gpio.level()) { | ||
std::cout << "quiting, bye bye\n"; | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <array> | ||
#include <iostream> | ||
#include <libhal-linux/i2c.hpp> | ||
#include <libhal-util/i2c.hpp> | ||
#include <libhal/error.hpp> | ||
#include <unistd.h> | ||
|
||
double rad_to_deg(double rad) | ||
{ | ||
return rad * 180 / 3.14; | ||
} | ||
|
||
void print_data(std::array<hal::byte, 6>& data) | ||
{ | ||
uint16_t x = data[0] << 8 | data[1]; | ||
uint16_t y = data[2] << 8 | data[3]; | ||
uint16_t z = data[4] << 8 | data[5]; | ||
std::cout << "X: " << x << " Y: " << y << " Z: " << z << std::endl; | ||
} | ||
|
||
void application() | ||
{ | ||
auto bus = hal::gnu_linux::i2c("/dev/i2c-1"); | ||
const auto addr = 0x68; | ||
const auto wake_sensor = std::array<hal::byte, 2>{ 0x6B, 0 }; | ||
hal::write(bus, addr, wake_sensor); | ||
const auto set_scale = std::array<hal::byte, 2>{ 0xC1, 1 }; | ||
while (true) { | ||
auto read_buffer = std::array<hal::byte, 6>{}; | ||
auto write_op = std::array<hal::byte, 1>{ 0x3B }; | ||
std::cout << "write_then_read:\n"; | ||
hal::write_then_read(bus, addr, write_op, read_buffer); | ||
// hal::write(bus, addr, write_op); | ||
// hal::read(bus, addr, read_buffer); | ||
print_data(read_buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include <libhal-linux/steady_clock.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/error.hpp> | ||
#include <unistd.h> | ||
|
||
void application() | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
auto sc = hal::gnu_linux::steady_clock<std::chrono::steady_clock>(); | ||
std::cout << "Clock made!\n"; | ||
for (int i = 0; i < 10; i++) { | ||
hal::delay(sc, 5s); | ||
std::cout << "Delayed for a second\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <libhal-linux/serial.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <span> | ||
#include <unistd.h> | ||
|
||
void application() | ||
{ | ||
std::cout << "UART test\n"; | ||
auto serial_file_path = "/dev/serial0"; | ||
auto serial_bus = hal::gnu_linux::serial(serial_file_path); | ||
std::string test_str = "Hello from libhal\n"; | ||
std::array<hal::byte, 255> input_buffer = { 0 }; | ||
while (true) { | ||
hal::print(serial_bus, test_str); | ||
sleep(1); | ||
auto read_res = serial_bus.read(input_buffer); | ||
if (input_buffer.at(0) == '\0') { | ||
std::cout << "Nothing to read\n"; | ||
continue; | ||
} | ||
std::cout << "Len of res buffer: " << read_res.data.size() | ||
<< " len of input buffer: " << input_buffer.size() << "\n"; | ||
auto subspan = read_res.data.subspan(0, read_res.data.size()); | ||
auto read_string = std::string(subspan.begin(), subspan.end()); | ||
sleep(1); | ||
std::cout << "Read from serial:" << read_string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.