Other articles


  1. C++: embedded driver code with static class and template

    #include <stdint.h>
    
    /* Base address of Device1 */
    #define DEVICE1 0x01234567
    
    struct MemoryMap {
            uint32_t Reg1;
            uint32_t Reg2;
    };
    
    template <uint32_t BASE_PTR>
    class MyDriver {
            public:
            static uint32_t MyMethod() {
                    return ((struct MemoryMap*)BASE_PTR)->Reg1;
            }
    };
    
    int main(int argc, char* argv[]) {
            uint32_t reg = MyDriver<DEVICE1>::MyMethod();
    
            return 0;
    }
    

    To avoid having to cast BASE_PTR all ...

    read more

Page 1 / 1