Take the GPIO registers for instance, a placement new approach could provide a zero overhead API to these registers and provide methods that abstract away some of the register’s unfriendliness. In the code below, I created a simple GPIOPort C++ class that maps the address of the registers of the GPIOB to a class that can use those registers. I created a couple of methods that let you set a pin high() or low() with zero code overhead. * the other methods are left as an exercise to the reader *
Maple Mini code * assumes PB1 is the led and it is active high *
// placement_new_blink - thin API to direct use of GPIO registers
inline void * operator new( size_t sz, void * here ) { return here;}
class GPIOPort : public gpio_reg_map {
public:
void high(const uint32_t pin_mask) { BSRR = pin_mask; }
void low(const uint32_t pin_mask) { BRR = pin_mask; }
};
static GPIOPort & portb = *(new ((void *)GPIOB_BASE) GPIOPort());
#define LED_MASK 1<<1
void setup() {
pinMode(PB1, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
portb.high(LED_MASK); // turn on led
delay(100); // wait
portb.low(LED_MASK); // turn on led
delay(900); // wait
}
* code without placement new *
// zero overhead API for register based manipulation
class GPIOPort : public gpio_reg_map {
public:
void high(const uint32_t pin) { BSRR = 1 << pin; }
void low(const uint32_t pin) { BRR = 1 << pin; }
};
static GPIOPort & portb = *((GPIOPort *)GPIOB_BASE);
#define LED_PORT_PIN PB1
#define LED_PIN 1 /* PB1 */
void setup() {
pinMode(LED_PORT_PIN, OUTPUT);
}
void loop() {
portb.high(LED_PIN); // turn on led
delay(100); // wait
portb.low(LED_PIN); // turn on led
delay(400); // wait
}
Since we know the chip flavor at compile time, can this knowledge not be used to normalise with alias (typedef) through a little bit of #ifdef magic?
Ray
A noble goal…
I think all of us want both flexibility (pin ss variable) and speed (pin mapped directly to port.) It is a shame that these seem to be mutually exclusive.
You must have been looking at my fabooh c++ template framework. ]
No, but I am a big fan of your work; esp. the BMP effort. As summer progresses and the wife’s to-do list becomes shorter, I hope to sacrifice a Mini to the BMP role… I had 30, gave 1 to an old friend who just had to have one (immediate gratification personality), and have 4 allocated to various on-bench projects… I have no problem tossing a virgin down the volcano as a sacrifice for the greater good.
Ray
You comment that without it, the code is better, but I would like to understand why. The main different I noticed is that it saves a few bytes, but I see both cases avoid calling digitalwrite, and all that digitalWrite calls by itself…
-rick
-rick
… not since college and 68000 and 6502 later on.
But, I do understand your explanation and it is helpful. Up until AVR, I had not worked with little chips and assembler since college in the mid-70’s. And with AVR, mostly only digging around in V-USB. I was fair at 6502 stuff back in my Apple II days, but never fancy enough to do anything other than xmodem stuff and a few helper routines for Applesoft. But everything was von Neumann – my comfort zone with Harvard is a bit shaky.
But; I am grateful for the explanation (makes sense) and I certainly am glad this forum have a bit-head on the team! Take care of your neurons, you’re a valuable asset.
Ray
… I had not worked with little chips and assembler since college in the mid-70’s…
Ray
… I had not worked with little chips and assembler since college in the mid-70’s…
Ray
Portable meant that you could lug it (puffing and wheezing) in and out of a Taxi, and use it as a seat on the train.
The spec is here. and I wrote a bunch of stuff including a print spooler and barcode printing utility (for hospital case notes). If you needed “speed” and “graphics”, that involved a lot of head scratching to talk to the “co-processor” and terminal board directly. I suspect one of these STM32F103C8XX chips would eat it for breakfast.
* Sadly, I fall into this same vintage as all the other old guys.
-rick

So I think with 41 years I’m a “youngster” here
BTW: I dreamt about this “portable” (but it wasn’t affordable for me in 1000 light years) :

(ok, this was 20 years later than the machines you posted, but – I think – equal if not more powerful than any STM32F1xx)
(( and yes, I was “ATARI” not commodore, because I needed MIDI))
2 Apple ][ with disk drives, all of the original Macintosh ( I added the last one after the pic was taken – so, all the monochrome units) and the CPM machine can just be seen in the right edge. The IIGS Woz edition has been donated.
The P.E.T. is in a different room. Somewhere on the server is a nice pix… but obviously not indexed!
Ray

- IMG_0282.JPG (52.32 KiB) Viewed 631 times

