Skip to content

stm32l1/i2c.c: adapt for new i2c periph driver interface#4096

Merged
thomaseichinger merged 1 commit intoRIOT-OS:masterfrom
ReneHerthel:stm32l1_i2c_opt
Dec 4, 2015
Merged

stm32l1/i2c.c: adapt for new i2c periph driver interface#4096
thomaseichinger merged 1 commit intoRIOT-OS:masterfrom
ReneHerthel:stm32l1_i2c_opt

Conversation

@ReneHerthel
Copy link
Copy Markdown
Contributor

Adaptation of the stm32l1/I2C driver for the optimized Interface

  • Original PR where the i2c periph driver interface was optimized.
  • Fixed the issue, that there works only the first I2C bus, now both should work.
  • This should be able to work with the new default I2C device access macro.
  • Removes some redundant defines/macros.
  • Added adaptation for nucleo-l1

@thomaseichinger thomaseichinger added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: drivers Area: Device drivers labels Oct 16, 2015
@thomaseichinger thomaseichinger added this to the Release NEXT MAJOR milestone Oct 16, 2015
@thomaseichinger
Copy link
Copy Markdown
Member

@ReneHerthel Great, would you mind also taking care of nucleo-l1?

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger This board should work with the same driver, or am I wrong? Or did you just mean I should test it with a nucleo-l1? Then I need one for testing.

@thomaseichinger
Copy link
Copy Markdown
Member

@ReneHerthel I'm sorry I was not clear, I meant to also adopt nucleo-l1/include/periph_conf.h as you did for limifrog-v1.

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Ah, okey :-). Only for I2C? I see there are only definitions for I2C_0 but not for I2C_1. I think I can adapt that, but I need a nucleo-l1 anyway for testing.

@thomaseichinger
Copy link
Copy Markdown
Member

That would be really great if you could add I2C_1 too. If you don't have access to a nucleo-l1 I could take the testing part.

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Think you can test it now.

@thomaseichinger
Copy link
Copy Markdown
Member

Ok great, one proposal: What do you think about changing the current approach to something like the UART configuration for the samr21-xpro board. Defining something comparable to uart_conf_t for I2C to hold the configuration defined in periph_conf.h. This way we'd save all these wrapping functions of if statements and replace it with array accesses. This would also limit maintenance to one file, periph_conf.h, if someone would like to change/add/remove a i2c device. So omit all _get_*(i2c_t dev) functions. What do you say?

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Sounds really interesting! I'll look at it later :-) think it could be a good idea

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Adapt, think this change makes sense :-)

@PeterKietzmann
Copy link
Copy Markdown
Member

@ReneHerthel what's the outcome of your thinking?
Edit: forget about my latest comment :-), it was by accident

@PeterKietzmann
Copy link
Copy Markdown
Member

@thomaseichinger may I assign you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a small comment that says which pin is which?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

Rebase.

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger I don't know how to add a mutex to the constant i2c_cfg array, any ideas? I adapt the other things.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReneHerthel you could add:

mutex_t mtx; /**< i2c config mutex */

here, and change the initialization of the config array [1] by appending the static mutex initializer MUTEX_INIT, e.g.:

{I2C2, GPIO_PIN(PORT_B, 10), GPIO_PIN(PORT_B, 11), 4,
     I2C2_EV_IRQn, I2C2_ER_IRQn, RCC_APB1ENR_I2C2EN, MUTEX_INIT},

(though this is untested, so don't know if this works)

[1] https://github.com/RIOT-OS/RIOT/pull/4096/files#diff-b7ca3df665fccc20bb1375fdb885cafbR246

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BytesGalore Yes I already tried this, but I got an error like: the i2c_cfg is constant and the Mutex is not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReneHerthel The following is untested but semantically it should be what we want:

typedef struct {
    const I2C_TypeDef *dev;       /**< pointer to the used I2C device */
    const gpio_t scl_pin;         /**< pin used for SCL */
    ...
    mutex_t mutex;
} i2c_conf_t;

and

static i2c_conf_t i2c_cfg[] = {
    {I2C2, GPIO_PIN(PORT_B, 10), GPIO_PIN(PORT_B, 11), 4,
     I2C2_EV_IRQn, I2C2_ER_IRQn, RCC_APB1ENR_I2C2EN, MUTEX_INIT},
...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaseichinger hmm okey. I'll Change that :)

@PeterKietzmann
Copy link
Copy Markdown
Member

@thomaseichinger can you please have a look at this? It would be really comfortable to merge this asap so we can test #3495 and #3263

@thomaseichinger
Copy link
Copy Markdown
Member

@PeterKietzmann I will have a look on the code, but I can't test for the next one and a half weeks as I don't have access to l1 board. Are #3495 and #3263 urgent?

@PeterKietzmann
Copy link
Copy Markdown
Member

Well, once your're happy with the code, we can test it here. The mentioned PRs are not urgent but I don't want Rene to lose his motivation ;-)

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Hmm I can compile that, don't know why, but okey! :-), think I did something wrong.. Thanks, it should work now.

BTW: I had to include mutex.h in periph_cpu.h, dont know if that is okey.

@thomaseichinger
Copy link
Copy Markdown
Member

@ReneHerthel It did compile because you where not using the mutex in i2c_cfg. But I figured this won't work as I though first. So please move back to ReneHerthel@269f35b and we should be able to get this through soon.

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@thomaseichinger Check.

@PeterKietzmann
Copy link
Copy Markdown
Member

@katezilla you need this PR for testing #3495 and #3263. Will you voluntary also take over this one :-D ? Thomas already did a code review. It's more about testing

@katezilla
Copy link
Copy Markdown
Contributor

yes, i can test it also

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@katezilla any news? :-) I thought you can test the limifrog drivers only with this here?

@thomaseichinger thomaseichinger added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Dec 1, 2015
@PeterKietzmann
Copy link
Copy Markdown
Member

@ReneHerthel as we discussed yesterday: please squash! AFAIK you and @katezilla successfully tested your PR

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

rebase.

@ReneHerthel
Copy link
Copy Markdown
Contributor Author

@PeterKietzmann @katezilla It is squashed now.

@PeterKietzmann PeterKietzmann added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Dec 2, 2015
@PeterKietzmann
Copy link
Copy Markdown
Member

We needed to put this again to the periph_conf, to satisfy travis:

 #define I2C_NUMOF           (2U)
 #define I2C_0_EN            1
 #define I2C_1_EN            1

@thomaseichinger ( @haukepetersen ) are you fine this way?!

@PeterKietzmann
Copy link
Copy Markdown
Member

BTW: Travis is green. So if you agree, we can merge this instantly

@thomaseichinger
Copy link
Copy Markdown
Member

ACK & Go

thomaseichinger added a commit that referenced this pull request Dec 4, 2015
stm32l1/i2c.c: adapt for new i2c periph driver interface
@thomaseichinger thomaseichinger merged commit 55f4013 into RIOT-OS:master Dec 4, 2015
@haukepetersen
Copy link
Copy Markdown
Contributor

I wonder if this PR works? Seems broken: The pins are defined as GPIO_PIN() -> #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y):

i2c_cfg[] = {... GPIO_PIN(PORT_B, 8)}

now the _pin_config() and _toggle_pin()` functions are called like this:

_pin_config(dev, GPIOB, i2c_cfg[dev].scl_pin, i2c_cfg[dev].sda_pin);

So i2c_cfg[dev].scl_pin is of type gpio_t, while the _pin_config() function expects just the pin number...
Further, the port is hard-coded here -> that should not be!

@PeterKietzmann
Copy link
Copy Markdown
Member

@ReneHerthel, @katezilla you told me your tests were successful, didn't you? Anyway, what you say seems logic, I will check...

@katezilla
Copy link
Copy Markdown
Contributor

Yes we tested it with the nucleo-l1 and a ultrasound Sensor, it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants