-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic DAC Driver, implementation on stm32f4discovery #2018
Conversation
@@ -0,0 +1,149 @@ | |||
/* | |||
* Copyright (C) 2014 Freie Universität Berlin | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's more your copyright or maybe HAWs.
Wow that PR came quick! Looks nice, I'll look and test in more detail later. |
#define DAC_0_PORT_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN) | ||
/* DAC 0 channel config */ | ||
#define DAC_0_CH0_PIN 4 | ||
#define DAC_0_CH1_PIN 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to careful with these pins, so far they are configured for ADC (PA4) and SPI SCK (PA6). Have a look at this table and check if you can find other pins. If not we need to see if we can re-arrange the pin mapping for the f4discovery board
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the stm32f4-family Reference Manual(Page 431)
http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf
Are the two DAC Channals hardwired to PortA Pin4 and 5. Not much possibility to choose anything else.
Congrats to you first PR! Besides some minor newline issues it looks very good! We just have to think about the pin mapping. So far the strategy was, not to map pins twice... |
PA4 and PA5 are the only pins for the DAC. I suggest to:
|
For completeness you should add |
I added periph_dac. Would be great if you change ADC_0_CH1_PIN and SPI_0_*, because I can't test the results here(I got no SPI Device here). |
Ok, again some funny design by ST... For this case I would actually leave the pin config for |
Ok maybe these ideas are totally stupid and "tinkering" but just to have a start of discussion:
|
@haukepetersen, how du you like this DAC interface? I think it's quite clear and in the style of your ADC interface. Just the return tyoes are a bit different. |
int8_t dac_write(dac_t dev, uint8_t channel, uint16_t value) | ||
{ | ||
DAC_TypeDef* dac = 0; | ||
uint16_t val = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis is unhappy:
cpu/stm32f4/periph/dac.c:86: style (unreadVariable): Variable 'dac' is assigned a value that is never used.
cpu/stm32f4/periph/dac.c:87: style (unreadVariable): Variable 'val' is assigned a value that is never used.
Maybe you could try to just initialize them without assigning a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try that to shutup Travis but i am sure thats considered bad style in c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simply guard the file with #if DAC_0_EN
instead of #if DAC_NUMOF
The interface is fine. I miss one thing in the return values (and in the implementation): The given |
DAC_0_PORT->MODER |= (3 << (DAC_0_CH0_PIN * 2) | 3 << (DAC_0_CH1_PIN * 2)); | ||
DAC_0_PORT->PUPDR &= ~(3 << (DAC_0_CH0_PIN * 2) | 3 << (DAC_0_CH1_PIN * 2)); | ||
break; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this like @haukepetersen commented:
default:
return -1;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for the other functions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed return values and documentation
Hi @brummer-simon, seems that you merged the master on-top of this branch. To rebase on the current master you first need to update your local master branch:
This way you have your master updated to the same state as the RIOT master. Now rebase your branch, i.e.
To resolve your situation:
I hope this helps a bit. |
33a25a3
to
6d785ed
Compare
Okay I rebased according to the upper comment. |
6d785ed
to
9e993a1
Compare
@brummer-simon we have a git cheatsheet where we included a howto [1] for rebasing lately (literally today). [1] https://github.com/RIOT-OS/RIOT/wiki/Git-cheatsheet#how-to-rebase-your-master-on-a-current-riot-master |
Finally the Travis CI build went well. As far as is see the only open Issue is the conflicting Pin configration. Any Ideas on this topic? |
#2076 looks like a compromise for the pin-problem |
@@ -1,2 +1 @@ | |||
FEATURES_PROVIDED += periph_gpio periph_spi periph_i2c periph_pwm periph_random periph_adc cpp | |||
|
|||
FEATURES_PROVIDED += periph_gpio periph_spi periph_pwm periph_random periph_adc periph_dac cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did the i2c go?
besides one question on the changed feature list I think we can merge this. If you could address this I give my ack |
Ok after this PR we can have a look at #2023 :-) |
Besides of the "pin-question" I'll give my ACK too but I think you should squash the commits |
7decfee
to
7296a87
Compare
From the commit messages both commits actually do more or less the same: is there a reason not to squash further? |
Interactive Mode doens't let me squash further. |
Try Edit: I had Brainlag - either the one above or |
7296a87
to
5a4b966
Compare
I managed to squash it to one commit after fiddeling around with git |
I'm happy that Travis is happy, finally! ACK ACK. Can someone please merge this and maybe also PR #2023 then?! |
and go. |
Basic DAC Driver, implementation on stm32f4discovery
dac_init(dac_t dev, dac_precision_t precision)
Initializing a DAC Device with a given precision, configures the Device and Channels.
dac_write(dac_t dev, uint8_t channel, uint16_t value)
Writes a value on a specific channel for a device.
dac_poweron(dac_t dev)
Enables a given DAC Device.
dac_poweroff(dac_t dev)
Disables a given DAC Device.
uint16_t dac_map(dac_t dev, int value, int min, int max)
Maps a integer value between interval min and max, to a valid integer to write onto the dac with respect to the selected precision.
uint16_t dac_mapf(dac_t dev, float value, float min, float max)
Maps a float value between interval min and max, to a valid integer to write onto the dac with respect to the selected precision.