Giter VIP home page Giter VIP logo

armpp's Introduction

armpp

armpp is a low-level C++ library designed to simplify the process of working with ARM32 hardware. The library is designed to replace traditional C code with more readable and equally efficient C++ code, providing an easier way to access and manipulate hardware via user-friendly C++ interfaces.

Features

The armpp library provides an assortment of classes that allow developers to interact with ARM32 hardware more conveniently. It's designed to be compatible with most ARM32 Cortex-M based Microcontrollers (MCUs).

However, it's currently being tested on an ARM32 Cortex-M3 core in a Gowin GW1NSR-4C FPGA development board TangNano 4K.

Register Fields

The library provides building blocks for constructing interfaces for various hardware.

registers.hpp contains templates for describing read-write, read-only and write-only register fields. The corresponding templates are:

template <concepts::register_value T, std::size_t Offset, std::size_t Size, /*...*/ >
struct read_write_register_field;

template <concepts::register_value T, std::size_t Offset, std::size_t Size, /*...*/ >
struct read_only_register_field;

template <concepts::register_value T, std::size_t Offset, std::size_t Size, /*...*/ >
struct write_only_register_field;

A couple of shortcut aliases are provided, ACCESSMODE in the following code stands for read_write, read_only and write_only:

/**
 * Integral value of arbitrary size and offset
 */
template <std::size_t Offset, std::size_t Size, /*...*/>
using raw_ACCESSMODE_register_field = ACCESSMODE_register_field<raw_register, Offset, Size, /*...*/>;

/**
 * Access individual bits at arbitrary offsets
 */
template <std::size_t Offset, /*...*/>
using bit_ACCESSMODE_register_field = ACCESSMODE_register_field<raw_register, Offset, 1, /*...*/>;

/**
 * Access individual bits as type boolean
 */
template <std::size_t Offset, std::size_t Size, /*...*/>
using bool_ACCESSMODE_register_field = ACCESSMODE_register_field<bool, Offset, Size, /*...*/>;

A register is constructed from the fields using union, for example, to implement a simple status register for a Gowin Cortex-M3 UART device, that contains 4 fields we can write:

union state_register {
    bool_read_only_register_field<0> tx_buffer_full;
    bool_read_only_register_field<1> rx_buffer_full;
    bool_read_write_register_field<2> tx_buffer_overrun;
    bool_read_write_register_field<3> rx_buffer_overrun;
};

The register fields can be used with integral types (signed and unsigned) and enumerations.

Prerequisites

To use the library, you will need to have the arm-none-eabi toolkit installed. I'm currently working on adding support for the clang toolkit. The library is built using cmake, and instructions for building from source will be provided later.

Getting Started

Examples and usage guidelines are currently under development and will be added in the future.

Hello World Program

#include <armpp/hal/uart.hpp>

extern "C"
int main()
{
    // This should be generated from IOC file
    armpp::hal::uart::uart_handle uart0{uart0_address, {.enable{.tx = true}, .baud_rate = 9600}};

    uart0 << "Hello world!\r\n";

    while(1) {}
}

Basic Timer Program

#include <armpp/hal/timer.hpp>
#include <armpp/hal/system.hpp>

extern "C"
int main()
{
    using sysclock = armpp::hal::system::clock;

    auto const& clock           = sysclock::instance();
    auto const  ticks_per_milli = clock.ticks_per_millisecond();

    // This should be generated from IOC file
    armpp::hal::uart::uart_handle uart0{uart0_address, {.enable{.tx = true}, .baud_rate = 9600}};
    armpp::hal::timer::timer_handle timer0{timer0_address, {.enable = false, .interrupt_enable = false}};

    while (1) {
        timer0.delay(ticks_per_milli * 5000);
        uart0 << sysclock::now().time_since_epoch() << " Hello there\r\n";
    }
}

Building the Library

The armpp library can be compiled from the source using cmake.

Detailed build instructions will be provided soon.

Known Issues

Currently, the library is only compatible with the arm-none-eabi toolkit. We are actively working on adding support for the clang toolkit.

Contributing

Contributions are welcome! We are currently developing guidelines for contributing, but if you're eager to contribute, feel free to create a pull request.

License

MIT License

For any issues, questions, or suggestions, please open an issue in the GitHub repository.

Please note that armpp is a work in progress, and some features may not be fully functional or complete. Check back often for updates, and thanks for your interest!

armpp's People

Contributors

zmij avatar

Watchers

 avatar

Forkers

alscode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.