https://github.com/madworm/MBI5030_demo … BI5030.cpp
The first error i get is
/home/flo/Arduino/libraries/MBI5030_demo/MBI5030.cpp:22:20: fatal error: avr/io.h: No such file or directory
#include <avr/io.h>
#include <avr/io.h>I deleted #include <avr/io.h> from MBI5030.cpp now I get this error again.
/home/flo/Arduino/libraries/MBI5030_demo/MBI5030.cpp: In constructor 'MBI5030::MBI5030(uint8_t, uint8_t, uint8_t, uint8_t)':
/home/flo/Arduino/libraries/MBI5030_demo/MBI5030.cpp:34:64: error: 'portModeRegister' was not declared in this scope
_spi_out_DIR = portModeRegister(digitalPinToPort(_spi_out_pin));
volatile uint32_t *pin1_io_port, *pin2_io_port;
uint16_t pin1_bitmask, pin2_bitmask;
...
#define PIN1 PA1
#define PIN2 PA2
#define pin1_set (*pin1_io_port = pin1_bitmask)
#define pin1_clear (*pin1_io_port = (pin1_bitmask<<16))
#define pin2_set (*pin2_io_port = pin2_bitmask)
#define pin2_clear (*pin2_io_port = (pin2_bitmask<<16))
...
(in setup):
pin1_io_port = portSetRegister(PIN1);
pin2_io_port = portSetRegister(PIN2)
pin1_bitmask = digitalPinToBitMask(PIN1);
pin2_bitmask = digitalPinToBitMask(PIN2);
...
(in main loop):
pin1_set;
pin2_clear;
...Then i can see if i can manage to code it regarding the structure you gave.
Mh perhaps I have to think a little. as I saw from your edit: I have to somehow edit the main file in the arduino ide instead of MBI5030.cpp…
_spi_out_DIR = portModeRegister(digitalPinToPort(_spi_out_pin));
_spi_out_PORT = portOutputRegister(digitalPinToPort(_spi_out_pin));
_spi_out_pinmask = digitalPinToBitMask(_spi_out_pin);You don’t need the DIR definitions.
What about pin input then?
I tried to reproduce a blink example with your code but it didnt work… Do you know why?
volatile uint32_t *pin1_io_port, *pin2_io_port;
uint16_t pin1_bitmask, pin2_bitmask;
#define PIN1 PB1
#define PIN2 PA2
#define pin1_set (*pin1_io_port = pin1_bitmask)
#define pin1_clear (*pin1_io_port = (pin1_bitmask<<16))
#define pin2_set (*pin2_io_port = pin2_bitmask)
#define pin2_clear (*pin2_io_port = (pin2_bitmask<<16))
void setup(void) {
pin1_io_port = portSetRegister(PIN1);
pin2_io_port = portSetRegister(PIN2);
pin1_bitmask = digitalPinToBitMask(PIN1);
pin2_bitmask = digitalPinToBitMask(PIN2);
}
void loop(void) {
pin1_set;
delay(1000);
pin1_clear;
delay(1000);
}
I could get it working somehow now. I used
gpio_set_mode(PIN_MAP[_spi_out_pin].gpio_device, PIN_MAP[_spi_out_pin].gpio_bit, GPIO_OUTPUT_PP);Can you try replacing them with the normal Arduino API calls like pinmode and digitalWrite , it would be more portable, and speed would not be an issue , as the STM32 runs at least 5x faster than AVR
Actually I doubt speed was ever an issue on AVR, as that function looks like a constructor
gpio_set_mode(PIN_MAP[_spi_out_pin].gpio_device, PIN_MAP[_spi_out_pin].gpio_bit, GPIO_OUTPUT_PP);typedef enum gpio_pin_mode {
/** Output push-pull. */
GPIO_OUTPUT_PP = GPIO_CR_CNF_OUTPUT_PP | GPIO_CR_MODE_OUTPUT_50MHZ,
/** Output open-drain. */
GPIO_OUTPUT_OD = GPIO_CR_CNF_OUTPUT_OD | GPIO_CR_MODE_OUTPUT_50MHZ,
/** Alternate function output push-pull. */
GPIO_AF_OUTPUT_PP = GPIO_CR_CNF_AF_OUTPUT_PP | GPIO_CR_MODE_OUTPUT_50MHZ,
/** Alternate function output open drain. */
GPIO_AF_OUTPUT_OD = GPIO_CR_CNF_AF_OUTPUT_OD | GPIO_CR_MODE_OUTPUT_50MHZ,
/** Analog input. */
GPIO_INPUT_ANALOG = GPIO_CR_CNF_INPUT_ANALOG | GPIO_CR_MODE_INPUT,
/** Input floating. */
GPIO_INPUT_FLOATING = GPIO_CR_CNF_INPUT_FLOATING | GPIO_CR_MODE_INPUT,
/** Input pull-down. */
GPIO_INPUT_PD = GPIO_CR_CNF_INPUT_PU_PD | GPIO_CR_MODE_INPUT,
/** Input pull-up. */
GPIO_INPUT_PU, /* (treated a special case, for ODR twiddling) */
} gpio_pin_mode;Some of these modes are our own extension to the Arduino API
I recall discussing getting Arduino to extend their API to include this sort of thing ( possibly not specifically the pinMode)
However, the people who run Arduino don’t seem interested in moving the API forward, despite the hardware availability greatly expanding over the last 5 years, e.g with the large numbers of MCUs now suooorted by 3rd part cores.
Especially devices like the ESP8266 and the ESP32 and the Teensy etc

