Revision 9466e34d

View differences:

Makefile
1
################################################################################
2
# AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous  #
3
# Mini Robot (AMiRo) platform.                                                 #
4
# Copyright (C) 2016..2019  Thomas Schöpping et al.                            #
5
#                                                                              #
6
# This program is free software: you can redistribute it and/or modify         #
7
# it under the terms of the GNU Lesser General Public License as published by  #
8
# the Free Software Foundation, either version 3 of the License, or            #
9
# (at your option) any later version.                                          #
10
#                                                                              #
11
# This program is distributed in the hope that it will be useful,              #
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
14
# GNU Lesser General Public License for more details.                          #
15
#                                                                              #
16
# You should have received a copy of the GNU Lesser General Public License     #
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.        #
18
#                                                                              #
19
# This research/work was supported by the Cluster of Excellence Cognitive      #
20
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is   #
21
# funded by the German Research Foundation (DFG).                              #
22
################################################################################
23

  
24

  
25

  
26
# absolute path to this directory
27
AMIROLLD_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
28

  
29
# include paths
30
AMIROLLD_INC = $(AMIROLLD_DIR) \
31
               $(sort $(dir $(wildcard $(AMIROLLD_DIR)include/?*/)))
32

  
33
# C sources
34
AMIROLLD_CSRC = $(shell find $(AMIROLLD_DIR)source/ -type f -regex "$(AMIROLLD_DIR)source/.+\.[Cc]")
35

  
drivers/A3906/v1/alld_A3906.c
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
/**
20
 * @file    alld_A3906.c
21
 * @brief   Motor driver functions.
22
 *
23
 * @addtogroup lld_motor
24
 * @{
25
 */
26

  
27
#include <alld_A3906.h>
28

  
29
/******************************************************************************/
30
/* LOCAL DEFINITIONS                                                          */
31
/******************************************************************************/
32

  
33
/******************************************************************************/
34
/* EXPORTED VARIABLES                                                         */
35
/******************************************************************************/
36

  
37
/******************************************************************************/
38
/* LOCAL TYPES                                                                */
39
/******************************************************************************/
40

  
41
/******************************************************************************/
42
/* LOCAL VARIABLES                                                            */
43
/******************************************************************************/
44

  
45
/******************************************************************************/
46
/* LOCAL FUNCTIONS                                                            */
47
/******************************************************************************/
48

  
49
/******************************************************************************/
50
/* EXPORTED FUNCTIONS                                                         */
51
/******************************************************************************/
52

  
53
/**
54
 * @brief Sets the power state of the A3906.
55
 * @param[in]   a3906d      The A3906 driver.
56
 * @param[in]   power_state The new power state to set.
57
 *
58
 * @return The return status indicates whether the function call was successfull.
59
 */
60
apalExitStatus_t a3906_lld_set_power(const A3906Driver* const a3906, const a3906_lld_power_t power_state)
61
{
62
  apalDbgAssert(a3906 != NULL);
63

  
64
  // set the output of the pin depending on the activation property
65
  return apalControlGpioSet(a3906->power_pin, (power_state == A3906_LLD_POWER_ON) ? APAL_GPIO_ON : APAL_GPIO_OFF);
66
}
67

  
68
/**
69
 * @brief Gets the current power state of the A3906.
70
 *
71
 * @param[in]   a3906d        The A3906 driver,
72
 * @param[out]  power_state   The currently set power state.
73
 *
74
 * @return The return status indicates whether the function call was successfull.
75
 */
76
apalExitStatus_t a3906_lld_get_power(const A3906Driver* const a3906, a3906_lld_power_t* const power_state)
77
{
78
  apalDbgAssert(a3906 != NULL);
79
  apalDbgAssert(power_state != NULL);
80

  
81
  // get current activation state of power gpio
82
  apalControlGpioState_t gpio_state;
83
  apalExitStatus_t status = apalControlGpioGet(a3906->power_pin, &gpio_state);
84
  *power_state = gpio_state == APAL_GPIO_ON ? A3906_LLD_POWER_ON : A3906_LLD_POWER_OFF;
85
  return status;
86
}
87

  
88
/**
89
 * @brief Set the PWM width for one channel.
90
 *
91
 * @param[in]   pwmd      The PWM driver to use.
92
 * @param[in]   channel   The channel of the given PWM driver to set.
93
 * @param[in]   width     The new width to set the PWM to.
94
 *
95
 * @return The return status indicates whether the function call was successfull.
96
 */
97
apalExitStatus_t a3906_lld_set_pwm(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width)
98
{
99
  apalDbgAssert(pwm != NULL);
100

  
101
  return apalPWMSet(pwm, channel, width);
102
}
103

  
104
/** @} */
105

  
drivers/A3906/v1/alld_A3906.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
/**
20
 * @file    alld_A3906.h
21
 * @brief   Motor driver macros and structures.
22
 *
23
 * @addtogroup lld_motor
24
 * @{
25
 */
26

  
27
#ifndef AMIROLLD_A3906_H
28
#define AMIROLLD_A3906_H
29

  
30
#include <amiro-lld.h>
31

  
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

  
36
/**
37
 * @brief Active state of power pin.
38
 */
39
#define A3906_LLD_POWER_PIN_ACTIVE_STATE  APAL_GPIO_ACTIVE_HIGH
40

  
41
/******************************************************************************/
42
/* SETTINGS                                                                   */
43
/******************************************************************************/
44

  
45
/******************************************************************************/
46
/* CHECKS                                                                     */
47
/******************************************************************************/
48

  
49
/******************************************************************************/
50
/* DATA STRUCTURES AND TYPES                                                  */
51
/******************************************************************************/
52

  
53
/**
54
 * @brief A3906 driver struct.
55
 */
56
typedef struct {
57
  const apalControlGpio_t* power_pin;   /**< @brief GPIO to enable/disable power of the A3906. */
58
} A3906Driver;
59

  
60
/**
61
 * @brief Power state of the A3906.
62
 */
63
typedef enum {
64
  A3906_LLD_POWER_OFF = 0x00,   /**< 'power off' state  */
65
  A3906_LLD_POWER_ON  = 0x01,   /**< 'power on' state   */
66
} a3906_lld_power_t;
67

  
68
/******************************************************************************/
69
/* MACROS                                                                     */
70
/******************************************************************************/
71

  
72
/******************************************************************************/
73
/* EXTERN DECLARATIONS                                                        */
74
/******************************************************************************/
75

  
76
#ifdef __cplusplus
77
extern "C" {
78
#endif
79
  apalExitStatus_t a3906_lld_set_power(const A3906Driver* const a3906, const a3906_lld_power_t power_state);
80
  apalExitStatus_t a3906_lld_get_power(const A3906Driver* const a3906, a3906_lld_power_t* const power_state);
81
  apalExitStatus_t a3906_lld_set_pwm(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width);
82
#ifdef __cplusplus
83
}
84
#endif
85

  
86
/******************************************************************************/
87
/* INLINE FUNCTIONS                                                           */
88
/******************************************************************************/
89

  
90
#endif /* AMIROLLD_A3906_H */
91

  
92
/** @} */
drivers/AT24C01B/v1/alld_AT24C01B.c
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
/**
20
 * @file    alld_AT24C01B.c
21
 * @brief   EEPROM function implementations.
22
 *
23
 * @addtogroup lld_eeprom
24
 * @{
25
 */
26

  
27
#include <alld_AT24C01B.h>
28
#include <string.h>
29

  
30
/******************************************************************************/
31
/* LOCAL DEFINITIONS                                                          */
32
/******************************************************************************/
33

  
34
/******************************************************************************/
35
/* EXPORTED VARIABLES                                                         */
36
/******************************************************************************/
37

  
38
/******************************************************************************/
39
/* LOCAL TYPES                                                                */
40
/******************************************************************************/
41

  
42
/******************************************************************************/
43
/* LOCAL VARIABLES                                                            */
44
/******************************************************************************/
45

  
46
/******************************************************************************/
47
/* LOCAL FUNCTIONS                                                            */
48
/******************************************************************************/
49

  
50
/******************************************************************************/
51
/* EXPORTED FUNCTIONS                                                         */
52
/******************************************************************************/
53

  
54
/**
55
 * @brief Acknowledgement polling to check if a write operation finished.
56
 * @param[in]   at24c01b  The eeprom driver to use.
57
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
58
 *
59
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
60
 */
61
apalExitStatus_t at24c01b_lld_poll_ack(const AT24C01BDriver* const at24c01b, const apalTime_t timeout)
62
{
63
  apalDbgAssert(at24c01b != NULL);
64

  
65
  uint8_t tmp = 0;
66
  return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), &tmp, 1, timeout);
67
}
68

  
69
/**
70
 * @brief Read the data from the eeprom starting at the current address.
71
 * @param[in]   at24c01b  The eeprom driver to use.
72
 * @param[out]  data      The data read from the AT24C01B.
73
 * @param[in]   num       The amount of bytes to read.
74
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
75
 *
76
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
77
 */
78
apalExitStatus_t at24c01b_lld_read_current_address(const AT24C01BDriver* const at24c01b, uint8_t* const data, const uint8_t num, const apalTime_t timeout)
79
{
80
  apalDbgAssert(at24c01b != NULL);
81
  apalDbgAssert(data != NULL);
82

  
83
  return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), data, num, timeout);
84
}
85

  
86
/**
87
 * @brief Read the data from the eeprom starting at a given address.
88
 * @param[in]   at24c01b  The eeprom driver to use.
89
 * @param[in]   addr      The address to read.
90
 * @param[out]  data      The data read from the AT24C01B.
91
 * @param[in]   num       The amount of bytes to read.
92
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
93
 *
94
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
95
 */
96
apalExitStatus_t at24c01b_lld_read(const AT24C01BDriver* const at24c01b, const uint8_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout)
97
{
98
  apalDbgAssert(at24c01b != NULL);
99
  apalDbgAssert(data != NULL);
100
  apalDbgAssert(addr + num <= AT24C01B_LLD_SIZE_BYTES);
101

  
102
  apalExitStatus_t status = apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), &addr, 1, NULL, 0, timeout);
103
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
104
    return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), data, num, timeout);
105
  } else {
106
    return status;
107
  }
108
}
109

  
110
/**
111
 * @brief Write a byte to the eeprom.
112
 * @param[in]   at24c01b  The eeprom driver to use.
113
 * @param[in]   addr      The address to start writing.
114
 * @param[out]  data      The data to be written to the AT24C01BN.
115
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
116
 *
117
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
118
 */
119
apalExitStatus_t at24c01b_lld_write_byte(const AT24C01BDriver* const at24c01b, const uint8_t addr, const uint8_t data, const apalTime_t timeout)
120
{
121
  apalDbgAssert(at24c01b != NULL);
122

  
123
  const uint8_t writedata[2] = {addr, data};
124
  return apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), writedata, 2, NULL, 0, timeout);
125
}
126

  
127
/**
128
 * @brief Write a page to the eeprom.
129
 * @param[in]   at24c01b  The eeprom driver to use.
130
 * @param[in]   addr      The address to start writing.
131
 * @param[in]   data      The data to be written to the AT24C01BN.
132
 * @param[in]   num       The amount of bytes to write.
133
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
134
 *
135
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
136
 */
137
apalExitStatus_t at24c01b_lld_write_page(const AT24C01BDriver* const at24c01b, const uint8_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout)
138
{
139
  apalDbgAssert(at24c01b != NULL);
140
  apalDbgAssert(data != NULL);
141

  
142
  uint8_t writedata[num+1];
143
  writedata[0] = addr;
144
  memcpy(&writedata[1], data, num);
145
  return apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), writedata, num+1, NULL, 0, timeout);
146
}
147

  
148
/** @} */
149

  
drivers/AT24C01B/v1/alld_AT24C01B.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
/**
20
 * @file    alld_AT24C01B.h
21
 * @brief   EEPROM macros and structures.
22
 *
23
 * @addtogroup lld_eeprom
24
 * @{
25
 */
26

  
27
#ifndef AMIROLLD_AT24C01B_H
28
#define AMIROLLD_AT24C01B_H
29

  
30
#include <amiro-lld.h>
31

  
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

  
36
/**
37
 * @brief Memory size of the EEPROM in bits.
38
 */
39
#define AT24C01B_LLD_SIZE_BITS              1024
40

  
41
/**
42
 * @brief Memory size of the EEPROM in bytes
43
 */
44
#define AT24C01B_LLD_SIZE_BYTES             128
45

  
46

  
47
/**
48
 * @brief Size of a page in bytes
49
 */
50
#define AT24C01B_LLD_PAGE_SIZE_BYTES        8
51

  
52
/**
53
 * @brief  Time in microseconds a write operation takes to complete (I2C will not respond).
54
 * @note   The system should wait slightly longer.
55
 */
56
#define AT24C01B_LLD_WRITECYCLETIME_US      5000
57

  
58
/**
59
 * @brief Maximum I2C frequency.
60
 */
61
#define AT24C01B_LLD_I2C_MAXFREQUENCY       400000
62

  
63
/**
64
 * @brief Maximum I2C frequency at 5V.
65
 */
66
#define AT24C01B_LLD_I2C_MAXFREQUENCY_5V    1000000