Yes, yes, yes! I'll never forget the first time I saw a compile error related to misuse of std::string. Horrible.
Compilers significantly improved this part since then.
As for other things: I see no point for discussion. I've explained an idea, if it not present an interest - no problem. But before it will be completely discarded, I'd like to show an example of how it might look like (note that it is based on existing libmaple/wiring API, so it does not completely implements ideas described above):
class Pin {
gpio_dev* dev;
uint8 pin;
gpio_reg_map *regs;
uint32 bit;
public:
Pin(gpio_dev* dev_, uint8 pin_):dev(dev_),pin(pin_), regs(dev->regs) { bit = BIT(pin);}
Pin(gpio_dev* dev_, uint8 pin_, gpio_pin_mode mode_):dev(dev_),pin(pin_), regs(dev->regs) { bit = BIT(pin); mod
inline void mode(gpio_pin_mode mode) {gpio_set_mode(dev, pin, mode);}
inline volatile uint32 __attribute__((always_inline)) read() {return (regs->IDR & bit) ? 1:0;}
inline void __attribute__((always_inline)) set() {regs->BSRR = bit;}
inline void __attribute__((always_inline)) reset() {regs->BRR = bit;}
inline void __attribute__((always_inline)) set(uint8 val) { if (val) regs->BSRR = bit; else regs->BRR = bit;}
inline void __attribute__((always_inline)) toggle() {regs->ODR ^= bit;}
};
Most methods are inline and translated in very short and effective code. Also, set of methods includes .set(<value>) along with simple .set().
Following example taken from one of my projects:
...
Pin Enable(GPIOB, ENABLE_PIN, GPIO_OUTPUT_PP);
...
if (button) {
Enable.reset();
setWorkingMode(MODE_MENU);
return;
}
Enable.set();
...