diff --git a/README.md b/README.md index a8116eb..029af2a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ LibBcm2835.Net ============== +This library is now deprecated. I advice that you use .NET Core and System.Device.Gpio from now on ;-) + +Description +----------- + A .NET/Mono Wrapper for Mike McCauley's C library for Broadcom BCM 2835 as used in Raspberry Pi ( http://www.airspayce.com/mikem/bcm2835/index.html ) @@ -76,7 +81,7 @@ License ------- The MIT License (MIT) -Copyright (c) 2017 Frank Hommers ( http://hmm.rs/LibBcm2835.Net ) +Copyright (c) 2020 Frank Hommers ( http://hmm.rs/LibBcm2835.Net ) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/LibBcm2835.Net/Bcm2835HeaderConverted.cs b/src/LibBcm2835.Net/Bcm2835HeaderConverted.cs index 74823b0..125dfac 100644 --- a/src/LibBcm2835.Net/Bcm2835HeaderConverted.cs +++ b/src/LibBcm2835.Net/Bcm2835HeaderConverted.cs @@ -46,6 +46,9 @@ public sealed partial class Bcm2835 public const UInt32 BCM2835_SPI0_BASE = 0x204000; public const UInt32 BCM2835_BSC0_BASE = 0x205000; public const UInt32 BCM2835_GPIO_PWM = 0x20C000; + public const UInt32 BCM2835_AUX_BASE = 0x215000; + public const UInt32 BCM2835_SPI1_BASE = 0x215080; + public const UInt32 BCM2835_SPI2_BASE = 0x2150C0; public const UInt32 BCM2835_BSC1_BASE = 0x804000; public const UInt32 BCM2835_PAGE_SIZE = (4 * 1024); public const UInt32 BCM2835_BLOCK_SIZE = (4 * 1024); @@ -315,6 +318,10 @@ public enum bcm2835RegisterBase BCM2835_REGBASE_BSC0 = 7, /// Base of the BSC1 registers. BCM2835_REGBASE_BSC1 = 8, + /// Base of the AUX registers. + BCM2835_REGBASE_AUX = 9, + /// Base of the SPI1 registers. + BCM2835_REGBASE_SPI1 = 10 } public enum bcm2835FunctionSelect { @@ -1347,8 +1354,9 @@ public void bcm2835_spi_end() private bcm2835_spi_setBitOrder_delegate _bcm2835_spi_setBitOrder_method; /// Sets the SPI bit order /// - /// NOTE: has no effect. Not supported by SPI0. - /// Defaults to + /// Set the bit order to be used for transmit and receive. The bcm2835 SPI0 only supports BCM2835_SPI_BIT_ORDER_MSB, + /// so if you select BCM2835_SPI_BIT_ORDER_LSB, the bytes will be reversed in software. + /// The library defaults to BCM2835_SPI_BIT_ORDER_MSB. /// see bcm2835SPIBitOrder /// /// The desired bit order, one of BCM2835_SPI_BIT_ORDER_*, @@ -1374,6 +1382,20 @@ public void bcm2835_spi_setClockDivider(UInt16 divider) } #endregion + #region "bcm2835_spi_set_speed_hz" + private delegate void bcm2835_spi_set_speed_hz_delegate(UInt32 speed_hz); + private void bcm2835_spi_set_speed_hz_unresolved(UInt32 speed_hz) { throw new MissingMethodException(); } + private bcm2835_spi_set_speed_hz_delegate _bcm2835_spi_set_speed_hz_method; + /// Sets the SPI clock divider by converting the speed parameter to + /// the equivalent SPI clock divider. (see bcm2835_spi_setClockDivider) + /// speed_hz The desired SPI clock speed in Hz + /// The desired SPI frequency + public void bcm2835_spi_set_speed_hz(UInt32 speed_hz) + { + _bcm2835_spi_set_speed_hz_method(speed_hz); + } + #endregion + #region "bcm2835_spi_setDataMode" private delegate void bcm2835_spi_setDataMode_delegate(Byte mode); private void bcm2835_spi_setDataMode_unresolved(Byte mode) { throw new MissingMethodException(); } @@ -1504,6 +1526,148 @@ public void bcm2835_spi_writenb([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UI } #endregion + #region "bcm2835_spi_write" + private delegate void bcm2835_spi_write_delegate(UInt16 data); + private void bcm2835_spi_write_unresolved(UInt16 data) { throw new MissingMethodException(); } + private bcm2835_spi_write_delegate _bcm2835_spi_write_method; + /// Transfers half-word to and from the currently selected SPI slave. + /// Asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) + /// during the transfer. + /// Clocks the 8 bit value out on MOSI, and simultaneously clocks in data from MISO. + /// Returns the read data byte from the slave. + /// Uses polled transfer as per section 10.6.1 of the BCM 2835 ARM Peripherls manual + /// The 8 bit data byte to write to MOSI + public void bcm2835_spi_write(UInt16 data) + { + _bcm2835_spi_write_method(data); + } + #endregion + + #region "bcm2835_aux_spi_begin" + private delegate Int32 bcm2835_aux_spi_begin_delegate(); + private Int32 bcm2835_aux_spi_begin_unresolved() { throw new MissingMethodException(); } + private bcm2835_aux_spi_begin_delegate _bcm2835_aux_spi_begin_method; + /// Start AUX SPI operations. + /// + /// Start AUX SPI operations. + /// Forces RPi AUX SPI pins P1-36 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) + /// to alternate function ALT4, which enables those pins for SPI interface. + /// + /// 1 if successful, 0 otherwise (perhaps because you are not running as root) + public Int32 bcm2835_aux_spi_begin() + { + return _bcm2835_aux_spi_begin_method(); + } + #endregion + + #region "bcm2835_aux_spi_end" + private delegate void bcm2835_aux_spi_end_delegate(); + private void bcm2835_aux_spi_end_unresolved() { throw new MissingMethodException(); } + private bcm2835_aux_spi_end_delegate _bcm2835_aux_spi_end_method; + /// End AUX SPI operations. + /// + /// SPI1 pins P1-36 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) + /// are returned to their default INPUT behaviour. + /// + public void bcm2835_aux_spi_end() + { + _bcm2835_aux_spi_end_method(); + } + #endregion + + #region "bcm2835_aux_spi_setClockDivider" + private delegate void bcm2835_aux_spi_setClockDivider_delegate(UInt16 divider); + private void bcm2835_aux_spi_setClockDivider_unresolved(UInt16 divider) { throw new MissingMethodException(); } + private bcm2835_aux_spi_setClockDivider_delegate _bcm2835_aux_spi_setClockDivider_method; + /// Sets the AUX SPI clock divider and therefore the AUX SPI clock speed. + /// The desired AUX SPI clock divider + public void bcm2835_aux_spi_setClockDivider(UInt16 divider) + { + _bcm2835_aux_spi_setClockDivider_method(divider); + } + #endregion + + #region "bcm2835_aux_spi_CalcClockDivider" + private delegate UInt16 bcm2835_aux_spi_CalcClockDivider_delegate(UInt32 speed_hz); + private UInt16 bcm2835_aux_spi_CalcClockDivider_unresolved(UInt32 speed_hz) { throw new MissingMethodException(); } + private bcm2835_aux_spi_CalcClockDivider_delegate _bcm2835_aux_spi_CalcClockDivider_method; + /// Calculates the input for \sa bcm2835_aux_spi_setClockDivider + /// A value between BCM2835_AUX_SPI_CLOCK_MIN and BCM2835_AUX_SPI_CLOCK_MAX + /// Input for bcm2835_aux_spi_setClockDivider + public UInt16 bcm2835_aux_spi_CalcClockDivider(UInt32 speed_hz) + { + return _bcm2835_aux_spi_CalcClockDivider_method(speed_hz); + } + #endregion + + #region "bcm2835_aux_spi_write" + private delegate void bcm2835_aux_spi_write_delegate(UInt16 data); + private void bcm2835_aux_spi_write_unresolved(UInt16 data) { throw new MissingMethodException(); } + private bcm2835_aux_spi_write_delegate _bcm2835_aux_spi_write_method; + /// Transfers half-word to and from the AUX SPI slave. + /// Asserts the currently selected CS pins during the transfer. + /// The 8 bit data byte to write to MOSI + public void bcm2835_aux_spi_write(UInt16 data) + { + _bcm2835_aux_spi_write_method(data); + } + #endregion + + #region "bcm2835_aux_spi_writenb" + private delegate void bcm2835_aux_spi_writenb_delegate([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len); + private void bcm2835_aux_spi_writenb_unresolved([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len) { throw new MissingMethodException(); } + private bcm2835_aux_spi_writenb_delegate _bcm2835_aux_spi_writenb_method; + /// Transfers any number of bytes to the AUX SPI slave. + /// + /// Asserts the CE2 pin during the transfer. + /// + /// Buffer of bytes to send. + /// Number of bytes in the tbuf buffer, and the number of bytes to send + public void bcm2835_aux_spi_writenb([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len) + { + _bcm2835_aux_spi_writenb_method(buf, len); + } + #endregion + + #region "bcm2835_aux_spi_transfern" + private delegate void bcm2835_aux_spi_transfern_delegate([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len); + private void bcm2835_aux_spi_transfern_unresolved([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len) { throw new MissingMethodException(); } + private bcm2835_aux_spi_transfern_delegate _bcm2835_aux_spi_transfern_method; + /// Transfers any number of bytes to and from the AUX SPI slave + /// + /// using bcm2835_aux_spi_transfernb. + /// The returned data from the slave replaces the transmitted data in the buffer. + /// (see also) bcm2835_spi_transfer() + /// + /// Buffer of bytes to send. Received bytes will replace the contents + /// Number of bytes int the buffer, and the number of bytes to send/received + public void bcm2835_aux_spi_transfern([MarshalAs(UnmanagedType.LPArray)]byte[] buf, UInt32 len) + { + _bcm2835_aux_spi_transfern_method(buf, len); + } + #endregion + + #region "bcm2835_aux_spi_transfernb" + private delegate void bcm2835_aux_spi_transfernb_delegate([MarshalAs(UnmanagedType.LPArray)]byte[] tbuf, [MarshalAs(UnmanagedType.LPArray)]byte[] rbuf, UInt32 len); + private void bcm2835_aux_spi_transfernb_unresolved([MarshalAs(UnmanagedType.LPArray)]byte[] tbuf, [MarshalAs(UnmanagedType.LPArray)]byte[] rbuf, UInt32 len) { throw new MissingMethodException(); } + private bcm2835_aux_spi_transfernb_delegate _bcm2835_aux_spi_transfernb_method; + /// Transfers any number of bytes to and from the AUX SPI slave. + /// + /// Asserts the CE2 pin during the transfer. + /// Clocks the len 8 bit bytes out on MOSI, and simultaneously clocks in data from MISO. + /// The data read read from the slave is placed into rbuf. rbuf must be at least len bytes long + /// Uses polled transfer as per section 10.6.1 of the BCM 2835 ARM Peripherls manual + /// (see also) bcm2835_spi_transfer() + /// + /// Buffer of bytes to send. + /// Received bytes will by put in this buffer. + /// Number of bytes in the tbuf buffer, and the number of bytes to send/received + public void bcm2835_aux_spi_transfernb([MarshalAs(UnmanagedType.LPArray)]byte[] tbuf, [MarshalAs(UnmanagedType.LPArray)]byte[] rbuf, UInt32 len) + { + _bcm2835_aux_spi_transfernb_method(tbuf, rbuf, len); + } + #endregion + #region "bcm2835_i2c_begin" private delegate int bcm2835_i2c_begin_delegate(); private int bcm2835_i2c_begin_unresolved() { throw new MissingMethodException(); } @@ -1805,6 +1969,7 @@ private void InitializeDelegates() _bcm2835_spi_end_method = GetDelegate("bcm2835_spi_end", bcm2835_spi_end_unresolved); _bcm2835_spi_setBitOrder_method = GetDelegate("bcm2835_spi_setBitOrder", bcm2835_spi_setBitOrder_unresolved); _bcm2835_spi_setClockDivider_method = GetDelegate("bcm2835_spi_setClockDivider", bcm2835_spi_setClockDivider_unresolved); + _bcm2835_spi_set_speed_hz_method = GetDelegate("bcm2835_spi_set_speed_hz", bcm2835_spi_set_speed_hz_unresolved); _bcm2835_spi_setDataMode_method = GetDelegate("bcm2835_spi_setDataMode", bcm2835_spi_setDataMode_unresolved); _bcm2835_spi_chipSelect_method = GetDelegate("bcm2835_spi_chipSelect", bcm2835_spi_chipSelect_unresolved); _bcm2835_spi_setChipSelectPolarity_method = GetDelegate("bcm2835_spi_setChipSelectPolarity", bcm2835_spi_setChipSelectPolarity_unresolved); @@ -1812,6 +1977,15 @@ private void InitializeDelegates() _bcm2835_spi_transfernb_method = GetDelegate("bcm2835_spi_transfernb", bcm2835_spi_transfernb_unresolved); _bcm2835_spi_transfern_method = GetDelegate("bcm2835_spi_transfern", bcm2835_spi_transfern_unresolved); _bcm2835_spi_writenb_method = GetDelegate("bcm2835_spi_writenb", bcm2835_spi_writenb_unresolved); + _bcm2835_spi_write_method = GetDelegate("bcm2835_spi_write", bcm2835_spi_write_unresolved); + _bcm2835_aux_spi_begin_method = GetDelegate("bcm2835_aux_spi_begin", bcm2835_aux_spi_begin_unresolved); + _bcm2835_aux_spi_end_method = GetDelegate("bcm2835_aux_spi_end", bcm2835_aux_spi_end_unresolved); + _bcm2835_aux_spi_setClockDivider_method = GetDelegate("bcm2835_aux_spi_setClockDivider", bcm2835_aux_spi_setClockDivider_unresolved); + _bcm2835_aux_spi_CalcClockDivider_method = GetDelegate("bcm2835_aux_spi_CalcClockDivider", bcm2835_aux_spi_CalcClockDivider_unresolved); + _bcm2835_aux_spi_write_method = GetDelegate("bcm2835_aux_spi_write", bcm2835_aux_spi_write_unresolved); + _bcm2835_aux_spi_writenb_method = GetDelegate("bcm2835_aux_spi_writenb", bcm2835_aux_spi_writenb_unresolved); + _bcm2835_aux_spi_transfern_method = GetDelegate("bcm2835_aux_spi_transfern", bcm2835_aux_spi_transfern_unresolved); + _bcm2835_aux_spi_transfernb_method = GetDelegate("bcm2835_aux_spi_transfernb", bcm2835_aux_spi_transfernb_unresolved); _bcm2835_i2c_begin_method = GetDelegate("bcm2835_i2c_begin", bcm2835_i2c_begin_unresolved); _bcm2835_i2c_end_method = GetDelegate("bcm2835_i2c_end", bcm2835_i2c_end_unresolved); _bcm2835_i2c_setSlaveAddress_method = GetDelegate("bcm2835_i2c_setSlaveAddress", bcm2835_i2c_setSlaveAddress_unresolved); diff --git a/src/LibBcm2835.Net/Bcm2835LibraryFileHelper.cs b/src/LibBcm2835.Net/Bcm2835LibraryFileHelper.cs index 80d60a2..0410b37 100644 --- a/src/LibBcm2835.Net/Bcm2835LibraryFileHelper.cs +++ b/src/LibBcm2835.Net/Bcm2835LibraryFileHelper.cs @@ -85,7 +85,7 @@ public static void ExtractAndCompileLibrary() try { - const string archivedLibFileName = "bcm2835-1.52.tar.gz"; + const string archivedLibFileName = "bcm2835-1.58.tar.gz"; string tempPath = Path.Combine(Path.GetTempPath(), System.Guid.NewGuid().ToString().ToLower()); string tempFileName = Path.Combine(tempPath, archivedLibFileName); createdDirectory = Directory.CreateDirectory(tempPath); diff --git a/src/LibBcm2835.Net/bcm2835-1.52.tar.gz b/src/LibBcm2835.Net/bcm2835-1.52.tar.gz deleted file mode 100644 index 90520d9..0000000 Binary files a/src/LibBcm2835.Net/bcm2835-1.52.tar.gz and /dev/null differ diff --git a/src/LibBcm2835.Net/bcm2835-1.58.tar.gz b/src/LibBcm2835.Net/bcm2835-1.58.tar.gz new file mode 100644 index 0000000..0fb3cd2 Binary files /dev/null and b/src/LibBcm2835.Net/bcm2835-1.58.tar.gz differ