Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
18605b36
Commit
18605b36
authored
Feb 21, 2015
by
danicampora
Browse files
cc3200: Rename SD.config() to SD.config_pins().
parent
7102e515
Changes
2
Hide whitespace changes
Inline
Side-by-side
cc3200/mods/pybsd.c
View file @
18605b36
...
...
@@ -49,10 +49,7 @@
#define PYBSD_FREQUENCY_HZ 15000000 // 15MHz
static
byte
pybsd_pin_d0
,
pybsd_pin_clk
,
pybsd_pin_cmd
;
static
byte
pybsd_af_d0
,
pybsd_af_clk
,
pybsd_af_cmd
;
static
const
pin_obj_t
*
pybsd_pin_sd_detect
;
static
bool
pybsd_pin_config_set
;
static
bool
pybsd_is_enabled
;
static
bool
pybsd_in_path
;
static
FATFS
*
sd_fatfs
;
...
...
@@ -63,20 +60,16 @@ void pybsd_init0 (void) {
ASSERT
((
sd_fatfs
=
mem_Malloc
(
sizeof
(
FATFS
)))
!=
NULL
);
}
bool
pybsd_is_present
(
void
)
{
if
(
pybsd_pin_sd_detect
)
{
return
pybsd_is_enabled
&&
MAP_GPIOPinRead
(
pybsd_pin_sd_detect
->
port
,
pybsd_pin_sd_detect
->
bit
);
}
return
true
;
return
pybsd_is_enabled
;
}
/******************************************************************************/
// Micro Python bindings
//
// Note: these function are a bit ad-hoc at the moment and are mainly intended
// for testing purposes. In the future SD should be a proper class with a
// consistent interface and methods to mount/unmount it.
/// \method sd_config([value])
/// Configure the pins used for the sd card.
...
...
@@ -91,9 +84,12 @@ bool pybsd_is_present(void) {
///
/// pyb.SDcard.sd_config_pins (d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af, card_detect_pin)
///
STATIC
mp_obj_t
pybsd_config
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
const
pin_obj_t
*
pin
=
NULL
;
STATIC
mp_obj_t
pybsd_config_pins
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
byte
pybsd_pin_d0
,
pybsd_pin_clk
,
pybsd_pin_cmd
;
byte
pybsd_af_d0
,
pybsd_af_clk
,
pybsd_af_cmd
;
const
pin_obj_t
*
pin
;
// get all the arguments
pin
=
pin_find
(
args
[
1
]);
pybsd_pin_d0
=
pin
->
pin_num
;
pybsd_af_d0
=
mp_obj_get_int
(
args
[
2
]);
...
...
@@ -106,42 +102,32 @@ STATIC mp_obj_t pybsd_config (mp_uint_t n_args, const mp_obj_t *args) {
pybsd_pin_cmd
=
pin
->
pin_num
;
pybsd_af_cmd
=
mp_obj_get_int
(
args
[
6
]);
pin_verify_af
(
pybsd_af_cmd
);
// configure the sdhost pins
MAP_PinTypeSDHost
(
pybsd_pin_d0
,
pybsd_af_d0
);
MAP_PinTypeSDHost
(
pybsd_pin_clk
,
pybsd_af_clk
);
MAP_PinTypeSDHost
(
pybsd_pin_cmd
,
pybsd_af_cmd
);
MAP_PinDirModeSet
(
pybsd_pin_clk
,
PIN_DIR_MODE_OUT
);
// configure the card detect pin if provided
if
(
n_args
==
8
)
{
pybsd_pin_sd_detect
=
pin_find
(
args
[
7
]);
pin_config
(
pybsd_pin_sd_detect
,
PIN_MODE_0
,
GPIO_DIR_MODE_IN
,
PIN_TYPE_STD_PU
,
PIN_STRENGTH_4MA
);
}
pybsd_pin_config_set
=
true
;
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pybsd_config_obj
,
7
,
8
,
pybsd_config
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pybsd_config_
pins_
obj
,
7
,
8
,
pybsd_config
_pins
);
STATIC
mp_obj_t
pybsd_enable
(
mp_obj_t
self
)
{
if
(
pybsd_pin_config_set
)
{
// Configure the D0 pin
MAP_PinTypeSDHost
(
pybsd_pin_d0
,
pybsd_af_d0
);
// Configure the CLK pin
MAP_PinTypeSDHost
(
pybsd_pin_clk
,
pybsd_af_clk
);
// Configure the CMD pin
MAP_PinTypeSDHost
(
pybsd_pin_cmd
,
pybsd_af_cmd
);
// Set the SD card clock as an output pin
MAP_PinDirModeSet
(
pybsd_pin_clk
,
PIN_DIR_MODE_OUT
);
// Enable SD peripheral clock
MAP_PRCMPeripheralClkEnable
(
PRCM_SDHOST
,
PRCM_RUN_MODE_CLK
|
PRCM_SLP_MODE_CLK
);
// Reset MMCHS
MAP_PRCMPeripheralReset
(
PRCM_SDHOST
);
// Initialize MMCHS
MAP_SDHostInit
(
SDHOST_BASE
);
// Configure the card clock
MAP_SDHostSetExpClk
(
SDHOST_BASE
,
MAP_PRCMPeripheralClockGet
(
PRCM_SDHOST
),
PYBSD_FREQUENCY_HZ
);
// Configure the card detect pin (if available)
if
(
pybsd_pin_sd_detect
)
{
pin_config
(
pybsd_pin_sd_detect
,
PIN_MODE_0
,
GPIO_DIR_MODE_IN
,
PIN_TYPE_STD_PU
,
PIN_STRENGTH_4MA
);
}
}
else
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
mpexception_os_resource_not_avaliable
));
}
// Enable SD peripheral clock
MAP_PRCMPeripheralClkEnable
(
PRCM_SDHOST
,
PRCM_RUN_MODE_CLK
|
PRCM_SLP_MODE_CLK
);
// Reset MMCHS
MAP_PRCMPeripheralReset
(
PRCM_SDHOST
);
// Initialize MMCHS
MAP_SDHostInit
(
SDHOST_BASE
);
// Configure the card clock
MAP_SDHostSetExpClk
(
SDHOST_BASE
,
MAP_PRCMPeripheralClockGet
(
PRCM_SDHOST
),
PYBSD_FREQUENCY_HZ
);
pybsd_is_enabled
=
true
;
// try to mount the sd card on /SD
...
...
@@ -176,7 +162,7 @@ STATIC mp_obj_t pybsd_disable(mp_obj_t self) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
pybsd_disable_obj
,
pybsd_disable
);
STATIC
const
mp_map_elem_t
pybsd_locals_dict_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_config
),
(
mp_obj_t
)
&
pybsd_config_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_config
_pins
),
(
mp_obj_t
)
&
pybsd_config_
pins_
obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_enable
),
(
mp_obj_t
)
&
pybsd_enable_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_disable
),
(
mp_obj_t
)
&
pybsd_disable_obj
},
};
...
...
cc3200/qstrdefsport.h
View file @
18605b36
...
...
@@ -162,7 +162,7 @@ Q(disable)
// for SD class
Q
(
SD
)
Q
(
config
)
Q
(
config
_pins
)
Q
(
enable
)
Q
(
disable
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment