logs archiveBotHelp.net / Freenode / #43oh / 2015 / September / 1 / 5
Spirilis
I see in fabooh where you have stuff defined based on mclk speed, etc. in the template args...
what I'm doing here - https://github.com/spirilis/AbstractWiring/blob/master/Implementations/msp430_value/UART_USCIA0.h - while that works, and the code works quite well with USCI_A0, I wouldn't want to copy & paste that code for every possible USCI_A[0123] I could get... I mean it wouldn't be that bad I guess but there's gotta be a nicer way with templates or whatever
Rickta59
yeah you could do that
i think i have some examples of doing that someplace
Spirilis
do templated classes always have to be defined as struct's?
Rickta59
or classes
Spirilis
or can template <blahblah> sit above class { };
ok
Rickta59
or functions
Spirilis
yeah that's going to be a huge help with this project
Rickta59
https://github.com/RickKimball/msp430_code/blob/master/fabooh/msp430/variants/msp430g2231in14/pins.h#L34
i took that approach .. * register names here *
https://github.com/RickKimball/msp430_code/blob/master/fabooh/msp430/variants/msp430g2231in14/pins.h#L71
same base template with different registers
then you can specialize for different things that aren't the norm
Spirilis
aah
nice
Rickta59
like the P2.6 P2.7
to initialize them is different than others
so every pin except those 2 use the common stuff .. and they override
Spirilis
how about that
neat
Rickta59
for setmode_input() .. setmode_output
be warned though
that is what broke their compiler because the template names include all the arguments
so the mangled name was > 256
Spirilis
oh
hm.
Rickta59
they fixed it now i think
they had a define in the msp430-as
and it is now bigger
Spirilis
yeah I may be running a version behind or so since I'm using a src-compiled ver from april I think
oh well I'll just have to test and see
Rickta59
when it fails you get a linker error
not a compiler error
the other approach is not to use the registers
https://github.com/RickKimball/fabooh/blob/master/include/cortex-m0/core/gpio.h#L111
so with the lpc1114fn28 ...
Spirilis
now when you define a class's definition in its .h file with template, in the .cpp file the template arguments become available for reference & use almost like private vars?
Rickta59
i decided to try something else
Spirilis
or symbols private to the class rather
Rickta59
the args are visible in the template yes
https://github.com/RickKimball/fabooh/blob/master/board/lpc1114fn28/pins.h#L13
so here .. in the lpc ports
i just used an integer
and then used that in a switch statement
but because it is a template it does the switch at compile time
in the switch statement i pick the base address depending on the number provided to the template
Spirilis
gotcha
I see that now
Rickta59
not sure which i like better
Spirilis
P0_PORTNO corresponds to an enum up above
Rickta59
either way works
yeah enum is key
being immutable allows the template to do compile time stuff
Spirilis
aye
ok gonna stash all my USCI_UART crap and try writing "USCI_UART" as a generic class
Rickta59
after you get done take a look at this
https://github.com/RickKimball/fabooh/blob/master/include/msp430/core/serial.h
and see if you come up with something similar
i was trying to abstract hw and software and timer based serial as something you could use interchangeably
Spirilis
yeah
in theory my "AbstractSerial" acts as a high level although Stream sits above both of those so I'm not sure it's needed
in fact I started using Stream pointers in my ircbot code a lot and it was nice
Rickta59
yeah being able to optimize the buffer stuff is useful too
Spirilis
the main thing AbstractSerial adds above Stream is begin, end, and an "extended" API that is optional but adds 7-bit, 2 stop bit, parity and break management
Rickta59
if you make that a class .. then you can make it pretty flexible
Spirilis
yeah
attachBreakInterrupt() might be neat
Rickta59
yeah .. or making the interrupt function something you pass
so it doesn't have to be called
Spirilis
that's how I am doing it
Rickta59
not the address
the implementation
Spirilis
ohh
gotcha
Rickta59
a struct { onInterrupt() { do something .. } };
hmm ..
i have something with timers that looks like what you are doing
but yeah .. i like that approach
http://dpaste.com/15ZENSH something liek that
http://dpaste.com/3BE4CT1 defined like that
http://dpaste.com/3T6CKF9 and the on_ccrx
the 'flatten' attribute .. takes and calls you make and forces them inline
so you can reduce call overhead
so the SysTickHandler "class" is called from the generic timer template because it is provided as a typename
so you can provide any functions without changing the core operation of the timer
but there is no function call overhead
as it gets all resolved at compile time
i was going to abstract out all the timer stuff into a common base timer class after i got it working the way i want
Spirilis
hmm, so struct's can hold methods and be passed around, i.e. code as data, just like in java?
Rickta59
hmm .. passed around
the way i used it there ..
it is a type ..
so i'm using the type as a template arg
and then when it compiles it resolves it
but yes
structs or classes
Spirilis
right cause either can be referenced as data "types"
nm I guess that's nothing mind blowing
« prev 1 2 3 4 5 6 7 8 next »