mock: mraa with mock platform now works in Windows under MSYS2
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
bcb6adc551
commit
1af737f3d9
@@ -106,7 +106,12 @@ enum iio_event_direction {
|
||||
};
|
||||
|
||||
//linux/iio/events.h
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#include <sys/ioctl.h>
|
||||
#else
|
||||
#include <linux/ioctl.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct iio_event_data - The actual event being pushed to userspace
|
||||
|
||||
48
docs/mock.md
48
docs/mock.md
@@ -35,3 +35,51 @@ CMake options.
|
||||
|
||||
To build under Linux, follow standard instructions, just make sure to set
|
||||
the `-DBUILDARCH="MOCK"` CMake option.
|
||||
|
||||
### Windows
|
||||
|
||||
Mocking capability allows us to build and use libmraa under Windows. That helps
|
||||
if you e.g. don't want to leave your customary Windows-based Python IDE, but
|
||||
want to develop libmraa-based programs.
|
||||
|
||||
Building Node.js bindings was not yet tested under Windows as MSYS2
|
||||
does not have a ready-made package. Java was not tested either.
|
||||
|
||||
#### Prerequisites
|
||||
|
||||
You'll need the following to build libmraa under Windows:
|
||||
|
||||
* [MSYS2](http://mingw-w64.org/doku.php/download/msys2) basic installation
|
||||
* Several additional packages, install them by running
|
||||
|
||||
```bash
|
||||
pacman -S cmake base-devel gcc git
|
||||
```
|
||||
|
||||
#### Compiling
|
||||
|
||||
The procedure is conceptually the same as under Linux - you first need to run
|
||||
CMake with specific options to generate makefiles and then run make to build everything.
|
||||
|
||||
* Run MSYS2 shell (not a MinGW one)
|
||||
* Clone the libmraa git repo (let's assume into `/home/test/mraa/mraa-src` dir)
|
||||
* Create a build directory outside of the clone one (let's say `/home/test/mraa/mraa-build`)
|
||||
* Run CMake, switching off unsupported options and enabling mock platform:
|
||||
|
||||
```bash
|
||||
cmake ../mraa-src/ -DBUILDARCH="MOCK" -DBUILDSWIGNODE=OFF -DENABLEEXAMPLES=OFF
|
||||
```
|
||||
|
||||
* Make, install and test:
|
||||
|
||||
```bash
|
||||
make clean && make install && make test
|
||||
```
|
||||
|
||||
All tests should pass.
|
||||
|
||||
**Note:** To have autocompletion in Python IDE, just point it to MSYS2's Python
|
||||
and make sure to specify any additional paths pointing to site-packages dir
|
||||
with mraa module if IDE requires that ("Interpreter Paths" in PyCharm).
|
||||
With the above settings the module will be installed into `/usr/local/lib/python2.7/site-packages`
|
||||
and the libmraa itself - into `/usr/local/bin`.
|
||||
|
||||
@@ -28,6 +28,8 @@ typedef struct {
|
||||
typedef void (*__kernel_sighandler_t)(int);
|
||||
typedef int __kernel_key_t;
|
||||
typedef int __kernel_mqd_t;
|
||||
#if !defined(MSYS)
|
||||
#include <asm/posix_types.h>
|
||||
#endif
|
||||
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
|
||||
#endif
|
||||
|
||||
58
include/linux/spi_kernel_headers.h
Normal file
58
include/linux/spi_kernel_headers.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This header was manually generated from a Linux kernel header
|
||||
* linux/spi/spidev.h, to make information necessary for compilation
|
||||
* to be available under MSYS. It contains only constants,
|
||||
* structures, and macros generated from the original header, and thus,
|
||||
* contains no copyrightable information.
|
||||
*/
|
||||
#ifndef _SPI_KERNEL_HEADERS_H
|
||||
#define _SPI_KERNEL_HEADERS_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define SPI_CPHA 0x01
|
||||
#define SPI_CPOL 0x02
|
||||
|
||||
#define SPI_MODE_0 (0|0)
|
||||
#define SPI_MODE_1 (0|SPI_CPHA)
|
||||
#define SPI_MODE_2 (SPI_CPOL|0)
|
||||
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
|
||||
|
||||
#define SPI_IOC_MAGIC 'k'
|
||||
|
||||
struct spi_ioc_transfer {
|
||||
__u64 tx_buf;
|
||||
__u64 rx_buf;
|
||||
|
||||
__u32 len;
|
||||
__u32 speed_hz;
|
||||
|
||||
__u16 delay_usecs;
|
||||
__u8 bits_per_word;
|
||||
__u8 cs_change;
|
||||
__u8 tx_nbits;
|
||||
__u8 rx_nbits;
|
||||
__u16 pad;
|
||||
};
|
||||
|
||||
#define SPI_MSGSIZE(N) \
|
||||
((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
|
||||
? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
|
||||
#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
|
||||
|
||||
#define SPI_IOC_RD_MODE _IOR(SPI_IOC_MAGIC, 1, __u8)
|
||||
#define SPI_IOC_WR_MODE _IOW(SPI_IOC_MAGIC, 1, __u8)
|
||||
|
||||
#define SPI_IOC_RD_LSB_FIRST _IOR(SPI_IOC_MAGIC, 2, __u8)
|
||||
#define SPI_IOC_WR_LSB_FIRST _IOW(SPI_IOC_MAGIC, 2, __u8)
|
||||
|
||||
#define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8)
|
||||
#define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8)
|
||||
|
||||
#define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32)
|
||||
#define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32)
|
||||
|
||||
#define SPI_IOC_RD_MODE32 _IOR(SPI_IOC_MAGIC, 5, __u32)
|
||||
#define SPI_IOC_WR_MODE32 _IOW(SPI_IOC_MAGIC, 5, __u32)
|
||||
|
||||
#endif
|
||||
@@ -104,6 +104,9 @@ endif()
|
||||
if (MOCKPLAT)
|
||||
add_subdirectory(mock)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMOCKPLAT=1")
|
||||
if (MSYS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMSYS=1")
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
if (USBPLAT)
|
||||
@@ -228,4 +231,9 @@ set_target_properties(
|
||||
SOVERSION ${mraa_VERSION_MAJOR}
|
||||
VERSION ${mraa_VERSION_STRING}
|
||||
)
|
||||
install(TARGETS mraa DESTINATION ${LIB_INSTALL_DIR})
|
||||
if (MSYS)
|
||||
# Under MSYS we have to put our generated DLL into bin, otherwise it's not picked up
|
||||
install(TARGETS mraa DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
else ()
|
||||
install(TARGETS mraa DESTINATION ${LIB_INSTALL_DIR})
|
||||
endif ()
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include "linux/i2c-dev.h"
|
||||
#include <errno.h>
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include "dirent.h"
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ if (PYTHON2_LIBRARY)
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
|
||||
endif()
|
||||
|
||||
@@ -18,7 +18,7 @@ if (PYTHON3_LIBRARY)
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH})
|
||||
endif ()
|
||||
|
||||
@@ -25,8 +25,17 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(MSYS)
|
||||
#define __USE_LINUX_IOCTL_DEFS
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(MSYS)
|
||||
// There's no spidev.h on MSYS, so we need to provide our own,
|
||||
// and only *after* including ioctl.h as that one contains prerequisites.
|
||||
#include "linux/spi_kernel_headers.h"
|
||||
#else
|
||||
#include <linux/spi/spidev.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -102,10 +102,12 @@ uint2speed(unsigned int speed)
|
||||
return B2500000;
|
||||
case 3000000:
|
||||
return B3000000;
|
||||
#if !defined(MSYS)
|
||||
case 3500000:
|
||||
return B3500000;
|
||||
case 4000000:
|
||||
return B4000000;
|
||||
#endif
|
||||
default:
|
||||
// if we are here, then an unsupported baudrate was selected.
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user