Commit graph

136 commits

Author SHA1 Message Date
Michael Hope 828facd2b7 Use stdint.h to define the basic types.
Solves a problem when building in strict C++ mode, as GCC defines
uint32_t as unsigned long on systems where sizeof(long) == 4.  This
causes GCC to complain that uint32 != uint32_t as unsigned int !=
unsigned long.

Signed-off-by: Michael Hope <michaelh@juju.net.nz>
2013-06-30 21:07:59 +02:00
Marti Bolivar 58794b59d4 Merge remote-tracking branch 'wesen/bug/usb-resume' 2013-04-26 12:49:55 -04:00
Manuel Odendahl 5315e3a239 Preserve previous usb state when suspending / restore on resume
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-04-26 11:12:03 +02:00
Manuel Odendahl 7446068400 Handle sending 0 byte packets.
Added a flag to see if we are currently waiting on an interrupt to acknowledge the sending of the current
IN packet.
Added a method usb_cdcacm_is_transmitting() to check for that flag.

Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 21:17:00 +01:00
Manuel Odendahl 699f97fdcb Move endpoint definitions to include files (they are now needed outside in usb_serial.cpp)
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 21:11:10 +01:00
Aditya Gaddam e77b2b7f46 "Callback versions of functions now take voidArgumentFuncPtr. We can probably use voidFuncPtr instead, but this way people can see that the function expects something different. Existing functions haven't changed in signature.
Signed-off-by: Aditya Gaddam <adityagaddam@gmail.com>"
2012-09-02 11:04:01 -04:00
Aditya Gaddam f6f2601213 "Added ability to set callbacks for interrupts that get an argument. This argument can be the instance that needs to handle the interrupt, or just a random argument you might find useful later. Suggestions from mbolivar and iperry from pull53 on libmaple were taken into account.
Signed-off-by: Aditya Gaddam <adityagaddam@gmail.com>"
2012-08-31 14:19:57 -04:00
Marti Bolivar e8c974423c Revert "Re-work the constraints on delay_us(). Ask GCC to allocate a register"
This reverts commit 715a63dccb. It fails
to build using the 2010 CodeSourcery toolchain, which is still the latest
officially supported version.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-22 17:05:04 -04:00
Michael Hope 715a63dccb Re-work the constraints on delay_us(). Ask GCC to allocate a register
instead of forcing r0.  Use the same operand as input and output to
remove the move.

Signed-off-by: Michael Hope <michael.hope@linaro.org>
2012-08-22 13:02:58 -04:00
Marti Bolivar a3a49c3ea9 Make PRIMASK set/clear functions __always_inline.
This is just to ensure that -Os doesn't prevent these from getting
inlined.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-14 11:35:01 -04:00
Marti Bolivar 7ea6af61a0 usb_cdcacm.h: Add convenience for declaring device descriptor.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:49 -04:00
Marti Bolivar 5692b97ad0 <libmaple/usb.h>: Fix usb_descriptor_string.
uint16 is the wrong type for the bString array.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:48 -04:00
Marti Bolivar cf6e56ed4e Move contents of usb_descriptors.h to <libmaple/usb.h>.
These form and name of structs etc. is basically determined by the USB
spec and the libmaple style guide, so there's little reason for them
to change, and less reason for them to stay hidden.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:46 -04:00
Marti Bolivar 5ac380615e Prep usb_descriptors.h for removal.
Just change names and things to fit the libmaple style. Its contents
will move to the top-level <libmaple/usb.h> header next.

This API is still unstable, but we need to expose pieces of it in
order to get the Maple-specific pieces of usb_cdcacm.c into Wirish.

Adjust uses of the API appropriately.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:45 -04:00
Marti Bolivar a97e9c14ed usb_cdcacm: Expose line coding state.
This was already supported, so just move the line coding structure to
the header and add some functions for accessing the current values.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 01:47:22 -04:00
Marti Bolivar b0a9e6fda2 usb_cdcacm: various fixups.
Mark internal state static. Properly reset the RX/TX state on USB
reset. Choose better names for countTx and newBytes.

Move the exposed configuration back into the .c; this information is
not beneficial to hooks.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 00:18:01 -04:00
Marti Bolivar 69cb5c65cb usb_cdcacm: Rename "notification" -> "management".
This keeps things in line with the specification, helping readability.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-01 13:42:08 -04:00
Marti Bolivar 6126bf5919 Move bootloader details out of libmaple.h.
Finally!

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 17:27:43 -04:00
Marti Bolivar 365f45679b Move bootloader reset signal detection to Wirish.
Use usb_cdcacm hooks to move the DTR edge and "1EAF" magic packet
detection to usb_serial.cpp. We'll later be able to extend this system
to support Leonardo-style reset signalling.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar ef1cc46487 usb_cdcacm: Add usb_cdcacm_peek().
We need this so the bootloader reset signal detector can look ahead in
the byte stream without stealing bytes from the user when "1EAF" isn't
received.

While we're doing this, take the time to fix a bunch of RX-related
code (dead code removal, adding volatile, etc.)

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 496e0566fa usb_cdcacm: Add hook system.
Provide hooks so users can reach into the CDC ACM callbacks with their
own code. We'll use this to move the bootloader reset signals to
Wirish.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 84468115ec usb_cdcacm: Expose some internal configuration and values.
Mark the API as unstable so people don't rely on these too hard. (This
header is not part of the official libmaple docs). We'll need some of
this configuration elsewhere later, and it doesn't make much sense to
expose it piecemeal.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar c6aa996912 <libmaple/scb.h>: Add FIXME to check for F2 compatibility.
Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 03:04:27 -04:00
Marti Bolivar fcdfeb495b <libmaple/scb.h>: Don't use BIT().
Also, assert copyright LeafLabs 2012.

Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 02:59:58 -04:00
Marti Bolivar f006ea136d <libmaple/scb.h>: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 02:58:33 -04:00
Marti Bolivar 50ee2097b3 Doxygen hacks and fixups.
- Shut Doxygen up in various places
- Fix some genuine docs bugs
- Ignore sources we're not responsible for

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-28 17:29:43 -04:00
Marti Bolivar d9d78c6bd3 <libmaple/i2c.h>: Add I2C_CCR_DUTY bit value definitions.
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 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 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 c00e9aea44 <libmaple/i2c.h>: Fix Doxygen.
Existing Doxygen was commenting I2C_IRQ_ERROR instead of
i2c_enable_irq(), as desired.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar ec096b7f7f libmaple/i2c.h: Better comments.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 385b4e0814 <libmaple/i2c.h>: Move low-level routines to end of file.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 449b7ceb76 I2C: Fix Doxygen F1-isms.
I'm not sure these functions should even exist in their present form,,
but I don't understand the code well enough to make a real fix. For
now, just replace references to RM0008 with "chip reference manual".

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 7aa5dd2d48 i2c_set_input_clk(): fix an F1-ism.
i2c_set_input_clk()'s documentation says that the maximum peripheral
clock frequency is 36 MHz, but that's a hard-coded magic number. The
actual limit is the device's APB frequency or 46 MHz, whichever is
lower (F2 and F4 share the 46 MHz limit).

Fix the documentation to reflect that fact, and add an internal
series-provided function to get the maximum clock frequency for a
device. To help users porting to F2, have i2c_set_input_clk()
assert-check that the provided frequency is less than that maximum
value and the hard 46 MHz limit.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 3e67141436 Move i2c_dev and i2c_state into new i2c_common.h.
This is necessary to add series-specific infrastructure to clean up
some F1-isms in <libmaple/i2c.h>'s inline functions.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 040595b919 libmaple/i2c.h: Cosmetics.
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 ec40c9ddc9 <libmaple/i2c.h>: Cosmetics.
Put CCR definitions after SR2, to keep them in register map order.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 2e32d86142 <libmaple/i2c.h>: Cosmetics.
Reorder register bit definitions by descending bit number, for
consistency with the rest of the library.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 38fdbf8d10 <libmaple/i2c.h>: Add missing register bit defns.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 74f4437188 libmaple/i2c.h: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 4efec065ff Fix I2C_CR2_FREQ bit definition.
The existing value clobbers the entire register.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar aac8e2ba2c libmaple/i2c.h: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 2031b7a50a libmaple/i2c.h: Don't use BIT().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar f7826ab473 <libmaple/dma.h>: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-21 23:17:24 -04:00
Marti Bolivar 2026ef2c36 DMA: prep for F2 with new "tube" API.
To prepare for STM32F2/F4 DMA support, introduce a new libmaple DMA
API, and move some code around to make priority level and interrupt
handling more generic.

The new API is based on a new set of types (dma_tube, struct
dma_tube_reg_map, enum dma_request_src, enum dma_cfg_flags, and struct
dma_tube_config).

The central abstraction is the dma_tube type. STM32F2/F4 use DMA
streams to control dataflow, and STM32F1 uses channels. dma_tube
stands for whichever is appropriate for the current target. Dealing
with tubes allows for configuring and using DMA with opaque tube
values in the same source, instead of (as with ST's firmware)
requiring two separate codebases.

The new API is also more user-friendly, as it doesn't require knowing
which DMA address registers to set and which configuration register
flags go along with them. It now suffices to specify the source and
destination for the DMA transfer, along with their sizes. This avoids
confusion (e.g. for memory-to-memory transfers, data flows from the
peripheral address register to the memory register, which might be
surprising on F2, which has two memory address registers).

The old API (based on enum dma_mode_flags and dma_setup_transfer()) is
still available on F1, but deprecate it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-15 17:41:34 -04:00
Marti Bolivar 78f2bb290b enum spi_mode: Add more descriptive enumerators, documentation.
Instead of requiring everyone to figure it out for themselves, add
enumerators specifying the idle logic level and what clock edge
triggers data capture. Yes, it's easy enough to figure it out. It's
also convenient to have these.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 21:47:46 -04:00
Marti Bolivar d71254f8f9 Bring back <libmaple/spi.h>.
Add a spi_private.h with a SPI_DEV(), for convenience. Use it in the
F1 and F2 implementations. We could probably unify these with an
STM32_HAVE_SPI(n) macro, but we'll leave that for the future.

Most everything from F1 is portable; F2 has some additional bit
definitions and a spi_get_af() routine, but that's about it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 21:46:25 -04:00