Commit graph

27 commits

Author SHA1 Message Date
Marti Bolivar 05e78fe0f5 I2C: Move CCR/TRISE config helper back to libmaple/i2c.c.
We can implement it in terms of _i2c_bus_clk() instead of hard-coding
STM32_PCLK1.

This might be overkill, since I2C peripherals are slow and thus likely
to be on APB1 for all STM32 devices (that is the case for F2/F4, for
instance), but if we're going to have _i2c_bus_clk(), we might as well
respect it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 15:07:08 -04:00
Marti Bolivar 0a54c3e336 i2c_dev: deprecate .gpio_port.
This won't work on F2, which at times has SDA and SCL on different
ports (e.g. I2C3 SDA on PC9, SCL on PA8). Add .sda_port and .scl_port
replacements, which are used when the now-deprecated .gpio_port is
null. Use them correctly everywhere, with some new i2c_private.h
helper functionality.

Sigh. The F1 I2C code tries too hard to guess what you wanted; it's
not porting well at all.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 52341e8ede I2C: Move nonportable CCR/TRISE configuration.
Do this via new private _i2c_set_ccr_trise().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar ae675749e0 I2C: Deprecate I2C_REMAP flag.
This is ad-hoc and nonportable. If you really want I2C mapped
elsewhere, then mess with the I2C device fields and call afio_remap()
yourself. (This is also cleaner for F2).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 56a593e8a5 I2C: Move F1-only errata workarounds out of libmaple/i2c.c.
The IRQ priority hack is unnecessary on targets with properly
functioning I2C IRQ handlers, so we shouldn't use it unless we have
to. Add a mechanism so a series header can provide such a hack if
necessary.  Have the F1 series header use this mechanism.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 88d2a4083d libmaple/i2c.c: Cosmetics.
Move private API to bottom of file.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 6d3f82b03f libmaple/i2c.c: Keep authorship straight.
I'm going to be moving a lot of code around without changing it soon,
so git blame will be unreliable.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 0bb2b3a282 I2C: Add i2c_config_gpios(), i2c_master_release_bus().
These are necessary to pull out some calls to gpio_set_mode().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 6335da211b libmaple/i2c.c: Replace throb() with ASSERT(0).
Calling throb() directly like that breaks the abstraction.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 209e31185c I2C: I don't think 10-bit addressing works.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 7c81947272 I2C: Restore on F1, refactoring prep for F2.
Bring back <libmaple/i2c.h> support on STM32F1 with a view towards how
it'll be implemented on STM32F2. There are still many F1-isms in
libmaple/i2c.c and <libmaple/i2c.h>, to be dealt with subsequently.

Move device declarations and base pointer definitions to a new F1
<series/i2c.h>. The register maps and bit definitions themselves are
identical on both series, so leave them in the libmaple header.

Add i2c_private.h, which contains:

- I2C_DEV(), a convenience macro for defining an i2c_dev, and
- declarations for the event and error IRQ handlers.

The IRQ handlers are large, and I2C is slow anyway, so I see no reason
to make them inline in the private header (as we do for some other
peripherals). We just expose the existing ones that were formerly
static in libmaple/i2c.c, but prefix the names with underscore.

Move the device declarations and IRQ handlers into new
stm32f1/i2c.c. These use the i2c_private.h API.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 413853aa44 libmaple/i2c.c: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 306e19cb9f Fix a bunch of Doxygen file-level comments.
Fix @file in many places. Also fix up the descriptions where it's
appropriate. This standardizes the @file formatting across the library
to explicitly include any parent directories up to the repository
root.

Besides being nice, this will hopefully let us manage Doxygen's XML
output so as to make extracting series-specific pieces via Breathe in
the leaflabs-docs repo possible.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-08 16:22:41 -04:00
Marti Bolivar 954f9e5065 Move public headers to include directories; related cleanups.
Move libmaple/*.h to (new) libmaple/include/libmaple/. The new
accepted way to include a libmaple header foo.h is with:

    #include <libmaple/foo.h>

This is more polite in terms of the include namespace. It also allows
us to e.g. implement the Arduino SPI library at all (which has header
SPI.h; providing it was previously impossible on case-insensitive
filesystems due to libmaple's spi.h).

Similarly for Wirish.

The old include style (#include "header.h") is now deprecated.

libmaple/*.h:

- Change include guard #defines from _FOO_H_ to _LIBMAPLE_FOO_H_.
- Add license headers where they're missing
- Add conditional extern "C" { ... } blocks where they're missing
  (they aren't always necessary, but we might was well do it against
  the future, while we're at it.).
- Change includes from #include "foo.h" to #include <libmaple/foo.h>.
- Move includes after extern "C".
- Remove extra trailing newlines

Note that this doesn't include the headers under libmaple/usb/ or
libmaple/usb/usb_lib. These will get fixed later.

libmaple/*.c:

- Change includes from #include "foo.h" to #include <libmaple/foo.h>.

Makefile:

- Add I$(LIBMAPLE_PATH)/include/libmaple to GLOBAL_FLAGS.  This allows
  for users (including Wirish) to migrate their code, but should go
  away ASAP, since it slows down compilation.

Wirish:

- Move wirish/**/*.h to (new) wirish/include/wirish/.  This ignores
  the USB headers, which, as usual, are getting handled after
  everything else.

- Similarly generify wirish/boards/ structure. For each supported
  board "foo", move wirish/boards/foo.h and wirish/boards/foo.cpp to
  wirish/boards/foo/include/board/board.h and
  wirish/boards/foo/board.cpp, respectively. Also remove the #ifdef
  hacks around the .cpp files.

- wirish/rules.mk: put wirish/boards/foo/include in the include path
  (and add wirish/boards/foo/board.cpp to the list of sources to be
  compiled). This allows saying:

      #include <board/board.h>

  instead of the hack currently in place. We can allow the user to
  override this setting later to make adding custom board definitions
  easier.

- Disable -Werror in libmaple/rules.mk, as the current USB warnings
  don't let the olimex_stm32_h103 board compile. We can re-enable
  -Werror once we've moved the board-specific bits out of libmaple
  proper.

libraries, examples:

- Update includes accordingly.
- Miscellaneous cosmetic fixups.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:50 -04:00
Marti Bolivar aad2377ae3 Update outdated stm32.h usages.
stm32.h has been updated to prefix its definitions.  Update the rest
of libmaple to take this into account.
2011-09-07 23:34:23 -04:00
Marti Bolivar 20c68e0eda i2c: Renaming, type changes, exposing i2c_init(), documentation.
Changes to struct i2c_dev members:

- uint8 clk_line's type is changing and is being renamed, is now
  rcc_clk_id clk_id
- uint8 ev_nvic_line's type is changing to nvic_irq_num
- uint8 er_nvic_line's type is changing to nvic_irq_num

Previous names were badly typed and inconsistent with the rest of
libmaple.

Exposing i2c_init(), also for consistency.

Adding/editing many Doxygen comments, for documentation and general
housekeeping.
2011-05-19 18:45:45 -04:00
Perry Hung c9775ff15c libmaple: Fix warnings in libmaple source files
-Add -Wall, -Werror to libmaple/*
-Fix warnings
2011-05-12 05:00:47 -04:00
Perry Hung 914db021c3 i2c: Various fixes, extensions, documentation.
-Fix clock calculations for fast-mode support
-Add I2C_REMAP option to remap i2c1 (untested)
-Add I2C_BUS_RESET option to reset bus on initialization
-Add optional timeout parameter
-Doxygen comments
-Various cleanup

10-bit slave addressing is untested until I have a device that speaks
such.
2011-05-12 04:07:33 -04:00
Marti Bolivar 39d4f043f1 I2C fixup.
Added i2c_init() for consistency with rest of libmaple.
2011-04-25 16:12:57 -04:00
Marti Bolivar a962d4f158 i2c cleanups.
Whitespace and column width changes only.
2011-04-14 14:00:47 -04:00
Marti Bolivar dc1b55a694 Making 1c05ac8497 comply with coding standard.
Whitespace corrections only.
2011-04-12 15:41:59 -04:00
Anton Eltchaninov 1c05ac8497 Adding i2c2 and i2c fast mode
Signed-off-by: Anton Eltchaninov <anton.eltchaninov@gmail.com>
2011-04-12 13:21:15 +07:00
Perry Hung 59f4a8a0df Merge branch 'i2c-wip' into refactor
Conflicts:
	examples/test-fsmc.cpp
	libmaple/rules.mk
	wirish/boards.h
2011-03-21 02:47:53 -04:00
Perry Hung 4d92849452 Add rudimentary error handling for nack condition 2011-03-14 22:52:06 -04:00
Perry Hung 3263998fca Fix merge error and compile error. 2011-03-11 00:45:33 -05:00
Perry Hung 6edf5c9aa2 Rename i2c irq handler to new naming convention. 2011-03-01 12:33:59 -05:00
Perry Hung 443953ac94 checkpoint 2011-02-26 22:30:22 -05:00