Skip to content

Commit 000d184

Browse files
committed
implement Wire.end() for SAM core
also moved common reset and disable code in libsam TWI_ConfigureMaster and TWI_ConfigureSlave functions to new TWI_Disable function, which is used in TwoWire::end()
1 parent 6967b75 commit 000d184

File tree

6 files changed

+68
-51
lines changed

6 files changed

+68
-51
lines changed

libraries/Wire/Wire.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ void TwoWire::begin(int address) {
126126
begin((uint8_t) address);
127127
}
128128

129+
void TwoWire::end(void) {
130+
TWI_Disable(twi);
131+
}
132+
129133
void TwoWire::setClock(uint32_t frequency) {
130134
twiClock = frequency;
131135
TWI_SetClock(twi, twiClock, VARIANT_MCK);

libraries/Wire/Wire.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929

3030
#define BUFFER_LENGTH 32
3131

32+
// WIRE_HAS_END means Wire has end()
33+
#define WIRE_HAS_END 1
34+
3235
class TwoWire : public Stream {
3336
public:
3437
TwoWire(Twi *twi, void(*begin_cb)(void));
3538
void begin();
3639
void begin(uint8_t);
3740
void begin(int);
41+
void end();
3842
void setClock(uint32_t);
3943
void beginTransmission(uint8_t);
4044
void beginTransmission(int);

system/libsam/include/twi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ extern void TWI_SetClock( Twi *pTwi, uint32_t dwTwCk, uint32_t dwMCk );
7171

7272
extern void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress);
7373

74+
extern void TWI_Disable(Twi *pTwi);
75+
7476
extern void TWI_Stop(Twi *pTwi);
7577

7678
extern void TWI_StartRead(

system/libsam/source/twi.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,8 @@ void TWI_ConfigureMaster( Twi* pTwi, uint32_t dwTwCk, uint32_t dwMCk )
100100

101101
/* SVEN: TWI Slave Mode Enabled */
102102
pTwi->TWI_CR = TWI_CR_SVEN ;
103-
/* Reset the TWI */
104-
pTwi->TWI_CR = TWI_CR_SWRST ;
105-
pTwi->TWI_RHR ;
106103

107-
/* TWI Slave Mode Disabled, TWI Master Mode Disabled. */
108-
pTwi->TWI_CR = TWI_CR_SVDIS ;
109-
pTwi->TWI_CR = TWI_CR_MSDIS ;
104+
TWI_Disable(pTwi);
110105

111106
/* Set master mode */
112107
pTwi->TWI_CR = TWI_CR_MSEN ;
@@ -156,15 +151,7 @@ void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress)
156151
{
157152
uint32_t i;
158153

159-
/* TWI software reset */
160-
pTwi->TWI_CR = TWI_CR_SWRST;
161-
pTwi->TWI_RHR;
162-
163-
/* Wait at least 10 ms */
164-
for (i=0; i < 1000000; i++);
165-
166-
/* TWI Slave Mode Disabled, TWI Master Mode Disabled*/
167-
pTwi->TWI_CR = TWI_CR_SVDIS | TWI_CR_MSDIS;
154+
TWI_Disable(pTwi);
168155

169156
/* Configure slave address. */
170157
pTwi->TWI_SMR = 0;
@@ -178,6 +165,27 @@ void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress)
178165
assert( (pTwi->TWI_CR & TWI_CR_SVDIS)!= TWI_CR_SVDIS ) ;
179166
}
180167

168+
/**
169+
* \brief Disables the TWI.
170+
* \param pTwi Pointer to an Twi instance.
171+
*/
172+
void TWI_Disable(Twi *pTwi)
173+
{
174+
assert( pTwi ) ;
175+
176+
uint32_t i;
177+
178+
/* TWI software reset */
179+
pTwi->TWI_CR = TWI_CR_SWRST;
180+
pTwi->TWI_RHR;
181+
182+
/* Wait at least 10 ms */
183+
for (i=0; i < 1000000; i++);
184+
185+
/* TWI Slave Mode Disabled, TWI Master Mode Disabled*/
186+
pTwi->TWI_CR = TWI_CR_SVDIS | TWI_CR_MSDIS;
187+
}
188+
181189
/**
182190
* \brief Sends a STOP condition on the TWI.
183191
* \param pTwi Pointer to an Twi instance.
546 Bytes
Binary file not shown.

variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pmc.o:
7272
00000000 T pmc_switch_udpck_to_upllck
7373

7474
pwmc.o:
75-
00000000 r C.9.8054
7675
00000000 t FindClockConfiguration
7776
00000000 T PWMC_ConfigureChannel
7877
00000000 T PWMC_ConfigureChannelExt
@@ -100,14 +99,14 @@ pwmc.o:
10099
00000000 T PWMC_SetSyncChannelUpdateUnlock
101100
00000000 T PWMC_WriteBuffer
102101
U __assert_func
103-
00000000 r __func__.6635
104-
00000000 r __func__.6646
105-
00000000 r __func__.6661
106-
00000000 r __func__.6672
107-
00000000 r __func__.6683
108-
00000000 r __func__.6690
109-
00000000 r __func__.6774
110-
00000000 r __func__.6780
102+
00000000 r __func__.6793
103+
00000000 r __func__.6804
104+
00000000 r __func__.6819
105+
00000000 r __func__.6830
106+
00000000 r __func__.6841
107+
00000000 r __func__.6848
108+
00000000 r __func__.6932
109+
00000000 r __func__.6938
111110

112111
rtc.o:
113112
00000000 T RTC_ClearSCCR
@@ -123,9 +122,9 @@ rtc.o:
123122
00000000 T RTC_SetTime
124123
00000000 T RTC_SetTimeAlarm
125124
U __assert_func
126-
00000000 r __func__.6632
127-
00000000 r __func__.6641
128-
00000000 r __func__.6646
125+
00000000 r __func__.6790
126+
00000000 r __func__.6799
127+
00000000 r __func__.6804
129128

130129
rtt.o:
131130
00000000 T RTT_EnableIT
@@ -134,8 +133,8 @@ rtt.o:
134133
00000000 T RTT_SetAlarm
135134
00000000 T RTT_SetPrescaler
136135
U __assert_func
137-
00000000 r __func__.6639
138-
00000000 r __func__.6647
136+
00000000 r __func__.6797
137+
00000000 r __func__.6805
139138

140139
spi.o:
141140
00000000 T SPI_Configure
@@ -161,9 +160,9 @@ tc.o:
161160
00000000 T TC_Start
162161
00000000 T TC_Stop
163162
U __assert_func
164-
00000000 r __func__.6634
165-
00000000 r __func__.6640
166-
00000000 r __func__.6646
163+
00000000 r __func__.6792
164+
00000000 r __func__.6798
165+
00000000 r __func__.6804
167166

168167
timetick.o:
169168
00000000 T GetTickCount
@@ -178,6 +177,7 @@ twi.o:
178177
00000000 T TWI_ByteSent
179178
00000000 T TWI_ConfigureMaster
180179
00000000 T TWI_ConfigureSlave
180+
00000000 T TWI_Disable
181181
00000000 T TWI_DisableIt
182182
00000000 T TWI_EnableIt
183183
00000000 T TWI_GetMaskedStatus
@@ -191,19 +191,20 @@ twi.o:
191191
00000000 T TWI_TransferComplete
192192
00000000 T TWI_WriteByte
193193
U __assert_func
194-
00000000 r __func__.7004
195-
00000000 r __func__.7010
196-
00000000 r __func__.7028
197-
00000000 r __func__.7032
198-
00000000 r __func__.7039
199-
00000000 r __func__.7043
200-
00000000 r __func__.7048
201-
00000000 r __func__.7056
202-
00000000 r __func__.7070
203-
00000000 r __func__.7075
204-
00000000 r __func__.7079
205-
00000000 r __func__.7084
206-
00000000 r __func__.7088
194+
00000000 r __func__.7151
195+
00000000 r __func__.7157
196+
00000000 r __func__.7172
197+
00000000 r __func__.7176
198+
00000000 r __func__.7184
199+
00000000 r __func__.7191
200+
00000000 r __func__.7195
201+
00000000 r __func__.7200
202+
00000000 r __func__.7208
203+
00000000 r __func__.7222
204+
00000000 r __func__.7227
205+
00000000 r __func__.7231
206+
00000000 r __func__.7236
207+
00000000 r __func__.7240
207208

208209
usart.o:
209210
00000000 T USART_Configure
@@ -222,7 +223,7 @@ usart.o:
222223
00000000 T USART_Write
223224
00000000 T USART_WriteBuffer
224225
U __assert_func
225-
00000000 r __func__.6928
226+
00000000 r __func__.7068
226227

227228
wdt.o:
228229
00000000 T WDT_Disable
@@ -300,7 +301,6 @@ startup_sam3xa.o:
300301
U main
301302

302303
adc.o:
303-
00000000 r C.0.8146
304304
00000000 T adc_configure_power_save
305305
00000000 T adc_configure_sequence
306306
00000000 T adc_configure_timing
@@ -485,12 +485,12 @@ efc.o:
485485
00000000 T efc_get_wait_state
486486
00000000 T efc_init
487487
00000000 T efc_perform_command
488-
00000070 T efc_perform_fcr
488+
0000006c T efc_perform_fcr
489489
00000000 T efc_perform_read_sequence
490490
00000000 T efc_set_flash_access_mode
491491
00000000 T efc_set_wait_state
492-
0000006c T efc_write_fmr
493-
00000000 b iap_perform_command.6909
492+
00000068 T efc_write_fmr
493+
00000000 b iap_perform_command.7049
494494

495495
gpbr.o:
496496
00000000 T gpbr_read
@@ -568,7 +568,6 @@ emac.o:
568568
00000000 T emac_phy_write
569569
00000000 t emac_reset_rx_mem
570570
00000000 t emac_reset_tx_mem
571-
00000000 t emac_wait_phy.clone.1
572571
00000000 b gs_rx_desc
573572
00000000 b gs_tx_callback
574573
00000000 b gs_tx_desc

0 commit comments

Comments
 (0)